I have just created my first token based web API with Django-Rest-Framework and it has worked really well for my mobile applications.
I am about to start creating a website based on Django, but I would like to reuse as much of my API code as possible.
The options I can see are:
How do you normally approach this kind of code reuse with Django?
Django REST Framework is used to create web APIs very easily and efficiently. This is a wrapper around over the Django Framework. There are three stages before creating an API through REST framework, Converting a Model’s data to JSON/XML format (Serialization), Rendering this data to the view, Creating a URL for mapping to the viewset.
Django REST Framework. Django REST framework is a powerful and flexible toolkit for building Web APIs. Some reasons you might want to use REST framework: The Web browsable API is a huge usability win for your developers. Authentication policies including packages for OAuth1a and OAuth2.
Click on the “GET” button and select “json” from the dropdown menu. This is what the raw JSON from our API endpoint looks like. I think we can agree the Django REST Framework version is more appealing. We covered a lot of material in this chapter so don’t worry if things feel a little confusing right now.
Django is a Python web framework that provides all the tools necessary for building modern web applications. In this tutorial, we are going to learn how to build a basic API that can be used to serve data to any client-side application including websites, mobile apps, desktop apps, and more.
This answer is based on my personal approach on the problem, both on industry and academic scenarios.
I value software decoupling. As such, I want to build smaller components, as reusable as possible. While presented with a similar problem, I've built the following components:
This approach allows to have different teams working each on their own (backend, mobile, web). I could enumerate tens of advantages of adopting such approach, but I've paved the way and you can consult literature if needed.
Good luck
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