top of page
Search
  • Writer's pictureSenthil Pitchappan V

REST API using Flask Framework

An API (Application Programming Interface) is a simple interface that defines the types of requests (demands/questions, etc.) that can be made, how they are made, and how they are processed.


In our case, we will be building an API that allows us to send a range of GET/ POST/ PUT/ PATCH/DELETE requests (more on this later), to different endpoints, and return or modify data connected to our API.

  1. Python

  2. Flask Web Framework

  3. REST API

  4. Postman


Setup:

Mainly we will be working on two endpoint users and locations. Two datasets containing users and location info. You can also use your own data from firebase or SQL or MongoDB.


pip install Flask
pip install flask-restful
pip install pandas

Endpoints:

  1. localhost/users

  2. localhost/locations

Flask Setup:

from flask import Flask
from flask_restful import Resource, Api, reqparse
import pandas as pd
import ast 

app = Flask(__name__)
api = Api(app)

GET:

Retrieve the URIs of the member resources of the collection resource in the response body. Retrieve a representation of the data in the response body.


POST:

Create a member resource in the collection resource using the instructions in the request body. The URI of the created member resource is automatically assigned and returned in the response Location header field.


PUT:

Replace all the representations of the member resources of the collection resource with the representation in the request body, or create the collection resource if it does not exist.


PATCH:

Update all the representations of the member resources of the collection resource using the instructions in the request body, or may create the collection resource if it does not exist.


DELETE:

Delete all the representations of the member resources of the collection resource.



Users Data:

  • Get

  • Post

  • Put

  • Delete


Locations Data:

  • Get

  • Post

  • Patch

  • Delete


Writing API Methods:


GET

http://127.0.0.1:5000/users
http://127.0.0.1:5000/locations


POST


DELETE

http://127.0.0.1:5000/users?userId=78945

Now, you have created a simple REST API Web Application using Flask. Later you can introduce Database and create a simple Blog Application using REST API.


9 views0 comments

Recent Posts

See All

Comments


bottom of page