Wrong Content Typ from controller

Hello everybody,
I always get the content Typ text/html From Rest Client Tool
I try to create a controller for my API thanks for help

$app = new \Slim\App(['settings' => ['displayErrorDetails' => true]]);
$container = $app->getContainer();
$container[\src\Controller\Opticancore::class] = function ($container) {
    return new \src\Controller\Opticancore($container);


use \Psr\Http\Message\ServerRequestInterface as Request;
use \Psr\Http\Message\ResponseInterface as Response;
class Opticancore {
 protected $ci;
    public function __construct($c) {
public function test(Request $request, Response $response){
$response =  $response->withHeader(
   'application/json; charset=utf-8'
return $response;

Restclient Response
text/html; charset=UTF-8

Why can I not set the content typ to application/json; charset=utf-8’ in the controller for the Response?

Setting the response seems to work fine using your example:

$ curl localhost:8000 -v
* Rebuilt URL to: localhost:8000/
*   Trying
* Connected to localhost ( port 8000 (#0)
> GET / HTTP/1.1
> Host: localhost:8000
> User-Agent: curl/7.47.0
> Accept: */*
< HTTP/1.1 200 OK
< Host: localhost:8000
< Connection: close
< X-Powered-By: PHP/7.0.4-7ubuntu2
< Content-type: application/json; charset=utf-8
< Content-Length: 14
* Closing connection 0

What headers and response body are you seeing?

I use a rest client Tool
it shows me following predefined

I have test with other client tool but it shows the same

It looks like you have empty lines as part of your response. Because of these lines, the PHP interpreter may conclude that outputting has started and will ignore any new headers.

Check your source code if you have empty lines before the “<?php" tag. Also omit the "?>” closing tag to avoid unintented output of empty lines.

Yes right, after this closing tag i had empty lines. Thx for help llvdl.