CodeIgniter Forums
RESTful responds and cookies - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: RESTful responds and cookies (/showthread.php?tid=87501)



RESTful responds and cookies - serialkiller - 04-26-2023

Is there a way when responding with $this->respond() (RESTful API), to both send a json array and also send a cookie?
For example, if I use $this->response(), I can do

PHP Code:
$this->response->setJSON(['var' => 'value']);

$this->response->setCookie($cookie);

return 
$this->response

is it possible somehow or I can't use RESTful Resource Handling in such cases, I can't find anything about it


RE: RESTful responds and cookies - kenjis - 04-26-2023

Try
PHP Code:
$this->response->setCookie($cookie);
return 
$this->respond($data200); 



RE: RESTful responds and cookies - serialkiller - 04-27-2023

(04-26-2023, 04:39 AM)kenjis Wrote: Try
PHP Code:
$this->response->setCookie($cookie);
return 
$this->respond($data200); 

It seems to work

Thanks kenjis