简体   繁体   中英

Do backend web service API's have a view as in MVC?

Lets's say I have a backend web API. It takes in a web request and returns some json. Other services then consume that json and do what they will with it.

My question is twofold:
1) Does this backend web API technically have a view (v in MVC)?
My thinking is no, since it doesn't actually display any frontend to the user.
2) Does the JSON object returned represent a model (m in MVC)?

Thanks!

1) Does this backend web API technically have a view (v in MVC)? My thinking is no, since it doesn't actually display any frontend to the user.

You are correct, it doesn't really have a View.

The Web API itself is simply going to return some data that was requested or something to indicate to the user that a request was performed properly (eg a JSON-formatted object indicating that a user was created, a collection of user objects, etc.)

Although a front-end could call the API and then use that information to render something, the Web API on it's own isn't going to do anything like that.

2) Does the JSON object returned represent a model (m in MVC)?

It can.

Each component of the MVC pattern plays an important role :

  • Controller - Responsible for things like data access and possibly populating a model.
  • Model - Responsible for representing the data that was accessed or for some type of operation.
  • View - Responsible for taking the model that was passed along from the controller and serving it to the user.

In this case, when you hit your Controller, you will likely be accessing some type of data and building a model. This model might use some business logic that you have designed yourself, or it might simply be content that was returned from your data layer, either way, the model, regardless of how it was created merely represents some type of data.

The "Model" is this case can be any type of data that you might decide to pass along to a View. Regardless of how it is serialized, if it is consumable either by a View or some other mechanism, you can think of it as a model.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM