samedi 27 février 2016

Can a REST API implement an MVC pattern

I need to build a REST API but it should implement a MVC pattern. But am confused what should go in the view section

I came up with the below architecture

1) .htacces will rewrite the URL and redirect to index.php 2) index.php will create an instance of httpkernal 3) httpkernal will do all the REST housekeeping and finally select the controller class and controller method depending on the request parameters 5) The View class will be created in the constructor of the Controller class and will be made available to all methods in the controller 6) controller class will have index ,store,update,destroy methods that will be called depending on the HTTP methods (GET,POST,PUT,DELETE) . These methods will intern call the respective models to do all the database operations. The data returned from the models will be passed to the view and the returned data will be returned back to the httpkernal 7) httpkernal will form the http header (success 200 ,error 400 ) depending on the return and print the output 8) Any exception throw anywhere will be caught by the httpkernal and a appropriate http header will be generated

Now the problem is what to put in the view. Actually why would I need a View? Can anyone help me with this? Or should I use a different architecture ? Thanks



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire