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

abdulaziz's avatar

Restful API

Hope you all doing good! I would like to make Restful API but I wonder how it must be used in the same project ? Do I make two types of Controller one will be for Restful API and another for returning views with jsons? What is the right way to do it? Thank you!

0 likes
3 replies
bobbybouwmann's avatar

If you're only going to use JSON you should be able to use your own API in your project. If you have an API and controllers with views you can split them. However if everything is JSON you're creating multiple endpoints for the same content, that would not make sense to me!

abdulaziz's avatar

I was wondering if it is possible to make something like this in Laravel. If yes, how the structure would look like

alt text

douglasakula's avatar

An all API business logic can work. If I was to implement this. I would create a client_identifier that can be passed in the header of the request. In this case client_identifier can be mobile os or browser or more precisely iOS, Windows,Android and browsers. Based on the client identifier - the API would handle the request and responses cycle differently. Say for client identifier browsers - a view is returned while for either of iOS, Windows or Android - a json string is returned.

Please or to participate in this conversation.