Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rest api instead of Views in Django

What is the main advantage of using REST api instead of views in Django

is that ok to mixing in REST api and Views(REST api in one app and Views in another app) ?

Or do we need to write REST api for all apps? instead of mixing REST and Views

like image 629
eranga Avatar asked Oct 20 '22 21:10

eranga


1 Answers

I am assuming you are asking about the advantages of a library like tastypie or django-rest-framework

I have never used tastypie, but for REST api's django-rest-framework provides a lot out of the box that makes development of these api's a lot quicker.

django-rest-framework provides things like:

  • model serializers (much like model forms, a shortcut to render model instances to user)
  • built in API authentication schemese
  • FREE web based documenation of your API ( just navigate to a resource in your browser! that easy)

From django-rest-framework site:

Some reasons you might want to use REST framework:

  • The Web browseable API is a huge usability win for your developers.
  • Authentication policies including OAuth1a and OAuth2 out of the box.
  • Serialization that supports both ORM and non-ORM data sources.
  • Customizable all the way down - just use regular function-based views if you don't need the more powerful features.
  • Extensive documentation, and great community support.

Ultimately, the main advantage, is that django-rest-api contains many tools to make it easier and faster to create rest apis. Everything that django-rest-api does you could implement yourself.


It is definitely ok to mix the two. Often times one django project will have an app that serves html content and another app that exposes the data through an API

like image 163
dm03514 Avatar answered Oct 24 '22 01:10

dm03514