jeudi 29 novembre 2018

Hiding the Model in MVC behind REST API

Let's start with an example:

A user is trying to create a new task in a ToDo MVC web app. When the user submits the new task, it, in an ideal scenario, gets validated by JS in the view, serverside in the controller, and then sent to the model via a REST API call. The web app can establish direct access to the database, if it wanted to, but it uses the established REST API to perform the CRUD operation and any final validation.

What are the advantages, disadvantages, or flaws with "hiding" the Model in an MVC web app behind a REST API, even if a direct connection to the DB is possible? Is doing this common practice?

An advantage I can think of is that you don't have to redefine the CRUD operations using direct DB connections if you already have a REST API.

A disadvantage would be the extra authentication that needs to happen for API calls, even if the web app user is logged in.

I'm new to designing REST API and MVC web apps, so I want to get some answers from the more experienced developers before I finalize my design for my current project which needs both a REST API and an MVC web app.

Aucun commentaire:

Enregistrer un commentaire