You might want to create an interface for other services to interact with your web application. By building an API, you can allow third parties to consume information and operate with your application programmatically.
An efficient way to share your data is to make it available through API.
An API (Application Programming Interface) is a set of URLs and parameters that is designed to be called by programs across the Internet.
The idea is that instead of receiving a full page of HTML designed for display, using an API programmers can ask for and get just the information they want and use it in their programs.
There are several ways you can structure your API but following REST principles is encouraged. The REST architecture comes from Representational State Transfer. RESTful APIs are resource-based. Your models represent resources and HTTP methods such as GET, POST, PUT, or DELETE are used to retrieve, create, update, or delete objects. HTTP response codes are also used in this context.
The Django REST Framework (or DRF) is a powerful module for building web APIs. It's very easy to build model-backed APIs that have authentication policies and are browsable.
DRF is a Third Party Application that we will use in conjunction with our own application to create a REST API. It provides us with many features that connect deeply with Django’s existing structures, helping us create RESTful HTTP resources that correspond to the models we create!
RESTful APIs are a structured set of HTTP resources. Those resources describe functions/database models and perform manipulation upon those structures via a set of standard HTTP requests.
These standards specify how URLs should be structured and what functions should happen based on a given HTTP methods. RESTful APIs should be structured such that all resources represent a data model. Methods supplied to the resource should be self explanatory. For example, GETing a resource should return all of values of that model.
You should structure all of your URLs to map to your database models to make it as RESTful as possible! You should NOT create resources that provide random arbitrary functions by requesting them.
One of the key advantages of command-line tools is that you can easily run again the HTTP requests again after we have built them for the first time, and we don't need to use the mouse or tap the screen to run requests. We can also easily build a script with batch requests and run them.
Curl, also known as cURL, is a very popular open source command-line tool and library that allows us to easily transfer data. We can use the curl command-line tool to easily compose and send HTTP requests and check their responses.
In Linux or macOS, you can open a Terminal and start using curl from the command line.
In Windows, you can install curl as part of the Cygwin package installation option and execute it from the Cygwin terminal.
Postman is a very popular API testing suite GUI tool that allows us to easily compose and send HTTP requests, among other features. Postman is available as a standalone app in Linux, macOS, and Windows. You can download the versions of the Postman app from the following.
You can download and install Postman for free to compose and send HTTP requests to the RESTful Web Services we will build. You just need to sign up to Postman.
The serialized data has to be rendered in a specific format before you return it in an HTTP response. Likewise, when you get an HTTP request, you have to parse the incoming data and de-serialize it before you can operate with it. REST framework includes renderers and parsers to handle that.
REST framework also includes Renderer classes that allow you to format API responses. The framework determines which renderer to use through content negotiation. It inspects the request's Accept header to determine the expected content type for the response. Optionally, the renderer is determined by the format suffix of the URL. For example, accessing will trigger the JSONRenderer in order to return a JSON response.