How to Send Text Data to Python FastAPI Using Postman

Hello Learners…

Welcome to the blog…

Topic: How to Send Text Data to Python FastAPI Using Postman

Table Of Contents

  • Introduction
  • What is FastAPI?
  • How to Send Text Data to Python FastAPI Using Postman
  • Summary
  • References

Introduction

In this post, we will explore how to send text data to a Python FastAPI application using Postman, a widely used API development tool. It is very useful when we are working with FastAPI.

What is FastAPI?

Python FastAPI is a popular web framework for building high-performance APIs. One common task when working with APIs is sending data to the server for processing.

How to Send Text Data to Python FastAPI Using Postman

Here we try to understand how to send the text data to FastAPI from the Postman tool.

If you don’t know about FastAPI you can learn from the below post,

To send text data first we have to create a FastAPI API.

First, we have to check whether Python is already installed or not.

This is the Python version that we used for this post.

Also, We require Postman installed on our system, If you don’t have Postman on your system then you can follow the below post and set up the Postman.

You can download it from here,

After that we have to install the required libraries,

pip install fastapi

we have to install uvicorn to run FastAPI Server using the pip command.

pip install "uvicorn[standard]"

Send Text Data As JSON or Python Dictionary To FastAPI From Postman

Now we create a send_text.py file and paste the below code into this file.

Here we write code that gives uppercase of our given text from Postman.

from fastapi import FastAPI
import uvicorn
app = FastAPI()

@app.get("/")
def hello():
    return {"API":"API is working fine"}

@app.post("/process_text")
async def process_text(text: dict):

    text_get=text['text']
    text_process=text_get.upper()
    return {"result":text_process,"message": "Text processed successfully"}

if __name__=="__main__":
    uvicorn.run(app)

Now we run the send_text.py file. To run the file,

python3 send_text.py

send text data to fastapi python using postman

It is running on port 8000 by default you can change it by the change in the line below.

uvicorn.run(app,port=5000)

We get an URL on our terminal

If you open it in your browser then we can see

This is the other function that we write into the code.

Now we open our Postman and Try to call our FastAPI.

We have to use http://127.0.0.1:8000/process_text to call that function and use the POST method.

In Postman Body > raw >JSON at that we have to pass our text.

Now Click on the Send button and below we can see the response of our FastAPI.

So this is the way we can send our text data to FastAPI from Postman and test our API response and after that, we can change it based on requirements.

Summary

In this post, we covered sending text data to a Python FastAPI application using Postman. By following these steps, you can easily send a text or other data to your FastAPI endpoints for processing and receiving the appropriate responses.

References

Leave a Comment