model-view-controllerweb-frameworks

MVC and API web frameworks


I don't quite understand the distinction between MVC and API web frameworks. For example, FAST API is called a tool for creating APIs, but can't a full-fledged web application be built on it by plugging in additional libraries? Isn't the web application itself an API? If Django has the Django REST Framework, which is positioned as a framework for building APIs, isn't the Django web application itself an API?

Maybe the web framework APIs just don't limit us to a structure, and we can work with the database and data representation however we want.


Solution

  • MVC and API frameworks are generally complimentary ideas. You can have a site that uses either one, or both, depending on what you want it to do.

    MVC (Model, View, Controller) frameworks typically occupy the "front end" portion of a web application, though sometimes the Model portion functions as the back end. For any given idea you want to represent you'll have a:

    It's important to note that MVC is not a strict rule for organizing your application: you might keep forms in their own module, or add a Service layer to contain more complex business logic. Real Python has a great article explaining the basic ideas and some example code at the end.

    An API (Application Programming Interface) can be used as, or be part of, the "back end" of a full stack web application. Any time you want to create, read, update, or delete (CRUD) persistent data that is stored on the server, you can use an API. API frameworks use different architecture, but typically they are RESTful (NB: I linked to Postman's blog because it's a very useful app for testing your own APIs).