Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP Slim Framework v3 - Set global content-type for responses

Is there a way to set the content-type to 'application/json' for responses globally in SLIM 3?

I tried the following things which did not work:

$app->contentType('application/json');
$app->response->headers->set('Content-Type', 'application/json');
like image 763
kernelpanic Avatar asked Feb 08 '23 00:02

kernelpanic


1 Answers

Middleware:

$app->add(function ($request, $response, $next) {
    return $response->withHeader('Content-Type', 'application/json');
});
like image 68
Brad Kent Avatar answered Feb 10 '23 09:02

Brad Kent