Sending status code in rest-api response
-
Hello Everyone,
I have installed the rest-api to serve the APIs to the frontend application. The res-apis only send the message in return of the success API and some big json in return of the failure. How can I send the status codes with the response so that frontend dev knows which kind of response if this?
Please share a way in which I do not loss my changes when I update the Bagisto and Dependencies in future.
Thank you -
Hello @marshalbagisto
We are using normal status codes like
1) 200 for all successful responses.
2) 422 for validation errors.
3) 500 for server errors
And if you need to add more key then you need to customize it at your end.
Or we can do it for you as a paid service for this you can purchase our hourly package,
https://store.webkul.com/bagisto-hourly-customization-package.html
Thanks & Regards
-
@Rishabh-Webkul Hi! I am not receiving even basic status codes in response. Can you please guide if I am using something wrong?
-
Hello @marshalbagisto
Can you provide us with a screenshot of the query and the response of the API
Thanks & Regards
-
@Rishabh-Webkul Please check the screenshot
-
@Rishabh-Webkul Hi! Anything on this?
-
Hello @marshalbagisto
Status Codes are not sent inside the response they were handled by Laravel and Axios
For 200 - return response()->json([|
'data' => $categories
], 200);
For 500 - return response()->json([|
'message' => 'Someting went wrong'
], 500);
and in your screenshot, we have marked, that your status code will be visible at this point as shown in the image below.
Thanks & Regards