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

Atef95's avatar

How to return status API

Hey guys

I would like to know how to return directly responses in API..

I mean let's say I'm fetching a user and I return 404 if he doesn't exist..

My response from the backend would be

$response->json(['status' => 404]);

so server returns 200 meaning it's fetched but then I have to test on

response.data.status == 404

I want directly something like

response.status == 404

how can I return that ?

I hope it's clear

0 likes
0 replies

Please or to participate in this conversation.