mardi 22 novembre 2016

What is the correct web application design with API?

Consider that we have a website and want to build a mobile app too.

The main model is the News model. The app so far may have 2 roles User and Admin. Normally I would build an api for the mobile. Suppose we use PHP and Laravel and create /api/news/create /store /delete and so on for a resource.

So far good, the mobile can call the api. What about the web? The code will be dublicated if I have a NewsController with the resource methods that I mentioned above for the api and another controller called PagesController which will have a method news and in this method it will fetch all news and display them. Maybe also accept params for filtering etc. It just doesn't make sense to dublicate the code...

On the other side I can use the API via web too by ajax, but ajax isn't an option because we want the news to get indexed.

What is a proper design in such cases?




Aucun commentaire:

Enregistrer un commentaire