Unparalleled suite of productivity-boosting Web APIs & cloud-based micro-service applications for developers and companies of any size.

API

Create your first REST API in Django Rest Framework

Django Rest Framework

Python, one of the most popular programming languages ​​today, is used for almost every subject in the field of informatics. Although we often hear the name of Python in the fields of artificial intelligence and data analysis, the use of Python is not limited to this. Especially when developing the REST API, Python’s Django Rest Framework provides developers with many conveniences.

What is Django Rest Framework

Django Rest Framework is an advanced framework that allows developers to code a common backend for both mobile applications, web applications, and desktop applications. For example, you can use a backend server that you coded with Django Rest Framework both in your mobile application and in your web application.

You can develop your applications by using Django Rest Framework with frontend technologies such as Angular, React, Vue. Since Django Rest Framework gives responses in a common structure in programming, you can use these outputs either with Angular or with React. So what type of output are these? Structures like JSON, of course. You can send these printouts in different structures upon request, of course, to the front end.

 

Creating a REST API in Django Rest Framework

Before you start developing the application, the Django Rest Framework library must be installed on your computer. If it is not installed, you can install it with the following command.

Django Rest Framework

Then we create a project with the following command.

Django Rest Framework

We are creating another layer in the default project with the following command, where we will perform REST API operations.

Django Rest Framework

After the API layer is created, we add “rest_framework” and “API” values ​​to the INSTALLED_APPS section in the Django project layer.

Django Rest Framework

Now let’s move on to preparing the REST API. Let’s paste the following into the API/views.py file.

Django Rest Framework

Now let’s paste the following into the djangoProject/urls.py file.

Django Rest Framework

Yes, we have added the REST API method we created to the project as a url and everything is ready to test.

Let’s run the following command from the command line.

python

After the application runs successfully, when we send an HTTP GET request to http://localhost:8000/helloworld/ via Postman, the response will be as follows.

Postman

Conclusion

That’s how easy it is to quickly create a REST API in minutes using Python’s Django Rest Framework. You can also prefer Django Rest Framework for your new projects.

Related posts
APICurrency

Exchange Rate API Integration in E-Commerce App in 2024

APICurrency

Building a Real-Time Currency Converter in Java Using Currencylayer API

API

10 Best Stocks APIs For Developers

API

Top 10 Flight Search APIs in 2024

Leave a Reply

Your email address will not be published. Required fields are marked *