Redirect toward a middleware

Hi,
I am working on a universitary project, a todolist in Slim4.

One constraint is to “simulate” an api rest to get tasks.

So when I arrive on my task page, I try to redirect temporary toward the Api page to get tasks:

$response = $response->withHeader('Content-Type','application/json')
                ->withHeader('Accept','application/json')
                ->withHeader('Accept-language','fr-FR')
                ->withHeader('Location','/api/Tasks/1');

The redirection works well but the headers I give to the request does not arrive to the Api page. When I print them I see they are not changed.

What’s wrong with my method ? I also tried with “withAddedHeader” but nothing change.

The actual response from the endpoint /api/Tasks/1 should contain the (Accept, …) headers for your API client, but not the redirect.

Thanks for your help. What is a good way to tell the API that I want a response in a specific language and in JSON ?

The Accept request HTTP header indicates which content types, expressed as MIME types, the client is able to understand. The server (Slim) uses “content negotiation” to select one of the proposals and informs the client of the choice with the Content-Type response header.

Your API client has to set this value for this header based on the context of the request.
For example: Accept: application/json.

How to Set Content Type to Application/JSON in Postman