» When to use RESTful APIs in a Django project
When to use RESTful APIs in a Django project
|September 6, 2014
Posted by forumadmin
I have a backend web application written with Django and a mobile application written with HTML/CSS/jQuery and wrapped in PhoneGap. I need the mobile app to communicate with the web app and I first thought I would build my own REST API.
WSGI is a specification (based on HTTP) that defines how to handle communications between a web server and a Python application, basically how to translate HTTP requests into Python objects and vice versa. All we need to provide to the WSGI server (
gunicorn for instance) is a WSGI application. In Django we will typically have a
wsgi.py file at the root of the project with
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
So Django has a built-in support for the WSGI specification and we, programmers, do not even have to think about how our application interfaces with the web server. Nice.
REST is an architecture style based on 6 constraints defining how data are transmitted between components within a program or separated programs (not necessarily web applications). A RESTful API is an API that fulfills those constraints. I heard that there is a whole framework for Django, surprisingly called
django-rest-framework, that helps developers to build REST APIs.
Hey, why would I need a REST API if the WSGI application already provides a way to parse HTTP requests and return responses? I mean, since my mobile application is nothing less than an embedded webpage, why can’t I just use regular urls to access my web application and return HTML code that depends on the type of device that sent the request?
If indeed a REST API is not needed in this case, what is the purpose of a REST API in a Django project? When is it useful?
More Related Questions
- django 1.6.5 + python3 wsgi problems When I try to run my django project as a wsgi application, I get the following error in my app's error log:
Exception ignored in: <module 'threading' from […]
- Calling RESTful API Using Python on Google App Engine I got some problems when calling RESTful webservice.
I'm running a Django 1.5 project on google app engine now.
And I make use of httplib in python to call a RESTful webservice.
- Token Authentication for RESTful API: should the token be periodically changed? I'm building a RESTful API with Django and django-rest-framework:
As authentication mechanism we've chosen "Token Authentication" and I have already […]
- What is best practice to serialize foreign key fields in a REST-ful api I want to write a Django app with a REST-ful api. Django REST framework offers three built-in model serializers: ModelSerializer which serializes to something like this
- Why dont Django and CherryPy support HTTP verb-based dispatch natively? It's not the same to POST to an URL than to GET it, DELETE it or PUT it. These actions are fundamentally different. However, Django seems to ignore them in its dispatch mechanism. […]
- View design for a Django website which has a RESTful API from the get go I am trying to build a Django powered website. I want the website to be dynamic. For example, I want the profile page for a authenticated user to contain multiple resources (like a friends […]
- Why is form.is_valid() evaluating false on POST request I am struggling with some prototype/test/learn like android app, that is supposed to GET and POST requests to a database via json/rest and django. I installed restless for django and the […]
- Web gateway interfaces in Python 3 I've finally concluded that I can no longer afford to just hope the ongoing Py3k/WSGI disasterissues will be resolved anytime soon, so I need to get ready to move on.
Unfortunately, my […]
- Cross Site Request Forgery in web services So I am working on a project where there is going to be a Security review to ensure that we are keeping certain data safe (student data to be specific). I personally don't need to worry […]
- Some basic questions about Django, Pyjamas and Clean URLs I am farily new to the topic, but I am trying to combine both Django and Pyjamas. What would be the smart way to combine the two? I am not asking about communication, but rather about the […]