Closed jancel closed 9 years ago
Yes you can set headers.
$app->response->headers['X-Foo'] = 'custome value';
For more details check Slim framework documentation http://docs.slimframework.com/
Are there other requirements to get the headers back to the browser. I tried to set content type for application/Jason and it is coming back as text/html still.
On Sunday, January 25, 2015, Constantin Botnari notifications@github.com wrote:
Yes you can set headers.
$app->response->headers['X-Foo'] = 'custome value';
For more details check Slim framework documentation http://docs.slimframework.com/
— Reply to this email directly or view it on GitHub https://github.com/Botnary/wp-slim-framework/issues/3#issuecomment-71408728 .
Jeff Ancel
(314) 703-8829 - Main
www.jeffancel.com
There are no other requirements, you can use Slim framework response object:
$response = $app->response();
$response->headers['Content-Type'] = 'application/json';
$response->headers['X-Powered-By'] = 'Potato Energy';
$response->status(200);
// etc.
$response->setBody(json_encode($dataAry));
or use the PHP old way
header("Content-Type: application/json");
echo json_encode($result);
exit;
Use a dev tool to check the headers in your browser.
Can we set the HTTP headers through this library? I'm having a fuss getting CORS requests working or content type set to json for the response. Hoping this can accomodate.