Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

panthro's avatar

API Reponse Type?

If my app returns a response from an api resource controller like:

return response([
            'message' => 'Deal successfully deleted.',
        ], 200);

This is turned into JSON automatically.

In my controller the docs have been auto stubbed with the comment:

* @return \Illuminate\Http\Response

But - is this the correct response type for the controller or would it be JSON or would it not as the JSON transformation happens later?

0 likes
1 reply
ctwillie77's avatar
Level 3

@panthro

The response() helper function returns \Illuminate\Http\Response::class, so you are right to put that in the doc block. And yes, json serialization happens after returning the Response class from the controller.

As long as the client making the request accepts json, nothing is wrong here.

1 like

Please or to participate in this conversation.