Giter VIP home page Giter VIP logo

fastapi-pingpong's Introduction

fastapi-pingpong

This is my testing of deployment for an app using FastAPI's framework while exploring both GET and POST Request APIs endpoints.

To test out this app, ensure that you have Docker, Docker Compose and curl installed.

Once you have the above installed, you can clone the repo into a local repo by typing the following instructions in the command line:

git clone https://github.com/kfoofw/fastapi-pingpong

# change to project repo
cd fastapi-pingpong

1. Build and Run the App using Docker-Compose.

Once within the directory itself, you can use Docker Compose to build the image and run it locally.

docker-compose up -d --build

The resultant container exposes the port of the localhost 8002 so this will be used in the following step.

2. API consumption/testing

The app itself can be explored in 2 ways with its RESTful APIs endpoints:

  • (a) GET Request on localhost:8002/ping
  • (b) POST Request on localhost:8002/what_is_ping

2(a) GET Request

Based on the GET Request, all you have to do is to type localhost:8002/ping on your browser and you should see the following:

{"ping":"pong!"}

Alternatively, you can also type in the following in the Terminal/command line:

curl localhost:8002/ping

and it should result in the following:

{"ping":"pong!"}

2(b) POST Request

With the POST Request, the app will return different output messages based on the input message.

To test the "right" message, you can type out the following in the Terminal/command line:

curl --data '{"message":"ping"}' --request POST localhost:8002/what_is_ping

and you should observe the following output:

{"ret_message":"Pong!"}

To test the "wrong" message, you can type out the following in the Terminal/command line:

curl --data '{"message":"not ping"}' --request POST localhost:8002/what_is_ping

and you should observe the following output:

{"ret_message":"No Ping so no Pong!"}

fastapi-pingpong's People

Contributors

kfoofw avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.