I'm now writing my engineering thesis about REST and REST APIs, mostly focusing on Django REST framework as it was the framework we used in our engineering project. I just finished writing about the guidelines for API to be RESTful stated by Roy Fielding and I wanted to start section with implementations of REST architecture in Django REST Framework, but then I realized I don't really know why this framework is RESTful. I know what main paradigms are for API to be RESTful, but I don't know what specific parts of framwork inplements for example that our service is stateless or layered. Maybe someone can pinpoint what parts of django rest framework corresponds to specified guidelines for service to be RESTful ? If It's wrong site to ask this type of question then I'm sorry, but any help would be greatly appreciated.
Let's go through the points that make API a RESTful one
1. Client-server architecture
The very essence of the fact that you are developing a backend server, which is not part of your application UI is the point of this client-server architecture.
Every app you develop with Django Rest Framework (from now on DRF) is a backend API, which is separated from the client.
2. Statelessness
I cannot pin point the exact code line that shows why DRF is statelessness but its somewhere deep between Django and the WSGI/ASGI interface.
Somewhere in there you have some kind of code like this:
while True:
request = io.listen_for_request()
response = handle_request(request)
return response
This "very pseudo" code is stateless! why? because we don't save or rely on any information between requests
3. Cacheability
This one is fairly simple, Django and DRF support caching link
4. Layered system
This concept is kinda hard to correlate directly to DRF or Django. This is mainly done through the HTTP protocol.
5. Code on demand (optional)
Servers can temporarily extend or customize the functionality of a client by transferring executable code: for example, compiled components such as Java applets, or client-side scripts such as JavaScript.
Basically Django Templates. It allows you to send forms and pages as part of your endpoints.
6. Uniform Interface
Last but not least, the famous uniform interface. DRF helps you build your REST API interface by creating endpoints with the help of Generic views. Those generic views help you create a full CRUD (create, read...) endpoint on a Django model with little to no effort. The created endpoint follows the Rest API interface of url structure for a resource.
Related
I am new to Python. I am aware of that, writing RESTful APIs would be easier and secure using some framework. There are already existing RESTful APIs of several 3rd parties. I need to develop RESTful APIs in Python which accepts request in JSON format, validates the request data and behind the scenes call the 3rd party APIs via CURL and sends the response received back to to the consumer in JSON format.
I have been able to do it in PHP using Codeigniter Framework.
Can anyone please provide suggestions on how to proceed for it, some tutorials link, best framework to move with.
Have shortlisted 3 frameworks,
1) Django REST Framework
Prerequisites - Knowledge of Django Framework (Obtained Just enough knowledge)
2) Bottle Framework (Micro framework) -
Explored a bit
3) Flask Framework (Micro framework) -
Yet not explored
Please note, I am having a very small learning curve of just about 5 days.
Please help.
I have backend of web app by django, include registrations/user profile,
the ability to add photo(video) file and view them, and list of places with the ability to book them.
Now I need to add the ability to work with a mobile application written in ReactJS.
The problem is that before that I did not work with mobile applications and I do not know what strategy to choose, but the frontend developer did not work with the backend. Can I pass django variables directly to the ReactJS code? Do I need additional technologies or frameworks? I would be grateful if someone shared their experience and described how to do it (preferably the least simple way)
You have to build a REST API. In your case, the best solution would be creating the API with Django REST Framework.
It is a very powerful framework for building APIs. They provide some nice tutorials to get started with it.
After that, you can create the frontend app with React by using API calls.
I've developed a couple of apps in Django and need to develop a moderately complex new app now. I've heard about AngularJS and I'm considering to use it in my new web app.
From research I have done so far, it seems like the main benefit of using Angular compared to plain Django is a better user experience. Are there any other major benefits that I need to take into account?
I would imagine the disadvantage of this is increased development time. Assuming I get past the Angular learning curve, how much longer will it take to develop the app in Django + Angular than purely in Django? (For instance 150% longer)
One last question is about using Django as the API framework. Effectively, I'm not using all of Django's features, but only a subset. Given this, is Django a good framework to create the API in? What are other alternatives should I consider?
Currently using a similar architecture for an app.
Backend is in Django and I'm using Django Rest Framework (DRF) to create REST resources. It's a highly powerful and customisable REST framework to create API resources.
From my understanding and experience, DRF works very well with any abstracted front end. So you can use the same APIs for any client be it browser or mobile apps. You can also serve the front end content in the same context as the Django backend or even separated. DRF has authentication methods for both types.
Resources: http://www.django-rest-framework.org/
As for learning curve, AngularJS isn't that difficult if you have basic understanding of the concepts of MV* as well as JavaScript. I won't be able to give you an exact time estimate but for me both methods would have lasted as long as each other.
As the basic framework core:
Request Lifecycle REST
Routing
Requests & Input
Views & Responses
Controllers
Errors & Logging
And these features would make our dev easy and fast:
Authentication
Cache
Core Extension
Events
Facades
Forms & HTML
IoC Container
Mail
Pagination
Queues
Security
Session
SSH
Templates
Unit Testing
Validation
And really good support for MongoDB.
Is there any such framework?
There is a fork of Django that supports non relational databases. For my own projects I prefer to use a hybrid: standard (relational) Django, with MongoEngine for entities I want to store in MongoDB. The syntax is almost identical to django.db models.
I'm kinda confused by the desire of a "REST lifecycle" combined with features like "Session", "Input", etc.
For a general purpose Web/API application you might want to check out on Flask and Flask-PyMongo. Could be a good match for your use case.
If you're looking into building a RESTful Web Service, then the Eve REST API framework (which is powered by Flask and supports MongoDB out of the box) could be a good choice. You can then peek into the source of extensions like Eve-Docs to learn how to, eventually, integrate the webservice with HTML/static/dynamic pages (Flask style.)
Try Django.. im not sure but worth trying
I'm trying to build a niche social network like Instagram as a Python/Django application.
So the things I need, regarding architecture, are (I guess):
REST API (e.g. api.mystagram.com).
Public website (www.mystagram.com or mystagram.com).
URL shortener (e.g. mystagr.am).
Android app
iPhone app
Windows Phone app
...
Before this I only built simple to some less-simple websites, but never extremely complex with own custom APIs or so. I have never build my own REST API before (I have used other REST APIs though) or even built an Android/iPhone app and distributed it in the Play Store/App Store (I have made some typical hello world examples though).
So, the most important thing to me seems to create a kick-ass REST API first and proceed from there. I am blocked however by a few questions.
How should I organize the projects for the public website and REST API? Should these be separate Django projects or should I create only one Django project and add both the public website and REST API as an internal Django module?
Should the public website also make use of the REST API? Or is it better to just use the plain Django models for this?
Thanks in advance for any help! If somebody knows some great presentations or so on this topic (architecture), always welcome!
Kind regards,
Kristof
Django REST Framework
https://github.com/tomchristie/django-rest-framework
Very well maintained, great documentation, easy to use.
I think Tastypie will do what you want. And its simple and easy. Check this out - http://django-tastypie.readthedocs.org/en/latest/!
To Answer your first question, It would be good practice to put public web site and REST APIs into one django project. Now days every web application contains public web site as well as rest apis for mobile app. So it would be easier to maintain both website and rest apis if they both in one application. Below is Django REST Framework link.
https://github.com/tomchristie/django-rest-framework
For second question, Yes you can use rest apis in website also. But in general you don't need to do it. In most of the cases django model works for you.