We earn commission when you buy through affiliate links.

This does not influence our reviews or recommendations.Learn more.

Before we proceed, lets understand the term JSON web tokens, REST API and Flask framework.

postman_signup

JSON is usually made up of three parts as the following.

JSON uses two types of structure forms when transferring data or information between two parties.

In the serialized form, there are three components.

Test the library api

The header component defines the cryptographic information about the tokens.

For example:

The deserialized form, unlike the serialized form, contains two components.

There are two popular types of APIs web and system API.

a user registers for an api

In this article, we will only look at the web API.

There are two types of web API.

REST API falls under the request-response category.

Article image

It makes use of HTTP methods such as GET, POST, and PUT to perform API operations.

The server then sends back the specific resource or collection of resources back to the user who requested it.

Flask Framework

Flask is a framework based on python.

Article image

It is a micro-framework used by python developers to build rest API.

Lets get it started with the implementation.

My system setup is as follows.

Article image

Lets use thevirtualenvto set up a new virtual environment.

Assuming you have thepipcommand available on your system, fire off the following command viapipto install.

If you dont have pip on your machine, then follow thisdocumentationto install pip on your system.

Article image

Next, lets create a directory to store or hold our virtual environment.

Execute all tasks related to this project within the virtual environment.

Create arequirements.txtfile with the following packages.

Article image

Install them with pip.

Set up a database

Lets install SQLite.

Paste the following code inside the file namedapp.py

The first line in the code above imports packages such asrequestandjsonify.

Article image

On the next line, we imported SQLAlchemy fromflask_sqlalchemyin order to integrate SQLAlchemy features into the flask.

Finally, we importeduuidalso known as universal unique identifiers to generate random id numbers for users.

Place the following code beneath the import statement.

Article image

When a user logs in, a random token is generated for the user to enter the library API.

Paste the code below beneath the previous route we created.

Still, within the virtual environment, create another route in theapp.pyfile to get or retrieve all registered users.

Inside the app.py file, create a route for registered users to create new authors.

Paste this code beneath the route which allows a user to retrieve all registered users.

Paste this code below the route which allows a user to create a new author.

Finally, still inside theapp.pyfile, create a route to delete a specified author as shown below.

Paste this code beneath the route which allows a user to retrieve a list of authors.

Afterward, save and shut the app.py file inside the virtual environment.

Apart from the postman, we can make use of other tools such asCurlto send requests to the server.