0

As I understand, a RESTful API aims to provide a communication layer for building on top of an application. Could the core application be build using the same REST logic?

So for example, build the REST architecture, and then implement all the database operations (CRUD) based on REST.

Therefore in an MVC application we have some controllers for implementing the REST service, like:

function Users(user_id){
    \\ return user with id = user_id
}

function Articles (article_id){
   \\ return article with id = article_id
}

And some controllers for handling the presentation. So if for example we want to list some articles in the homepage:

function homepage (){
   for ($i=0; $i<10; $i++)
   {
      \\ request  'http://www.example.com/articles/' . $some_article_id;  
   }
   \\ output to view
}

Not sure if the above makes sense, but the main point is that we add another layer in the MVC architecture, so that the presentation-logic Controllers no longer communicate directly with the models, but only through the REST Controllers:

In an MVC approach the data flow is:

presentation Controller ----> Model ----> presentation Controller ----> View

In an MVC - REST approach the data flow would be:

presentation Controller ----> REST Controller ----> Model ----> REST Controller ----> presentation Controller ----> View

Do you see any disadvantages in the above approach? I believe that it would simplify coding but I searched a lot and haven't found any further info.

1 Answer 1

2

Yes there are many disadvantages.
- HTTP is intended for transfer of large grain resources.
- Implementing database transactions across HTTP requests is problematic, to say the least.
- You are using HTTP where is really isn't necessary and potentially introducing performance issues

and architecturally it is just the wrong place to use REST. See this article for a more in-depth discussion of why you should not attempt to expose your domain objects using REST.

Sign up to request clarification or add additional context in comments.

2 Comments

In the past few days I'm switching from CodeIgniter to Rails and also read this article. Now I see how silly my question was.
@Zack You're question was not silly at all. I would say the majority of people attempting to implement REST apis are making the same mistake.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.