I've got a Django application that works nicely. I'm adding REST services. I'm looking for some additional input on my REST strategy.
Here are some examples of things I'm wringing my hands over.
Please nominate one approach per answer so we can vote them up or down.
Django Rest Framework is a powerful library that sits on top of existing Django projects to add robust web APIs. If you have an existing Django project with only models and a database--no views, urls, or templates required--you can quickly transform it into a RESTful API with a minimal amount of code.
Django REST framework (DRF) is a powerful and flexible toolkit for building Web APIs. Its main benefit is that it makes serialization much easier. Django REST framework is based on Django's class-based views, so it's an excellent option if you're familiar with Django.
Django Rest Framework makes it easy to use your Django Server as an REST API. REST stands for "representational state transfer" and API stands for application programming interface. Note that with DRF you easily have list and create views as well as authentication.
I'm thinking of falling back to simply writing view functions in Django that return JSON results.
Please note that REST does not just mean JSON results. REST essentially means exposing a resource-oriented API over native but full-fledged HTTP. I am not an expert on REST, but here are a few of the things Rails is doing.
For example, to get the native HTTP support going, the server should respond to
GET /account/profile HTTP/1.1 Host: example.com Accept: application/json
as it would respond to
GET /account/profile.json HTTP/1.1 Host: example.com
And it should respond to
PUT /account/profile HTTP/1.1 Host: example.com var=value
as it would respond to
POST /account/profile HTTP/1.1 Host: example.com _method=PUT&var=value
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With