Skip to content

Latest commit

 

History

History
78 lines (52 loc) · 2.74 KB

File metadata and controls

78 lines (52 loc) · 2.74 KB

FastAPI, in a nutshell

First part of this talk should be covering why FastAPI may suit your product needs.

What we'll be covering:

1) A quick crash course in: API endpoints, API parameters, Request/Responses.

2) Setup: Python setup (optional), Installing FastAPI

3) Creating your first endpoint (GET)

4) Testing your first endpoint (localhost:8000/docs)

5) Creating an endpoint with API parameters

A QUICK CRASH COURSE IN THE WORLD OF APIs

API endpoints types (GET/POST/DELETE/PATCH)

GET

We use this endpoint to fetch data

POST

We use this endpoint to send complete data

DELETE

We use this endpoint to delete data

PATCH

We use this endpoint to update data

API Parameters (Path/Query)

Path Parameters

You can think of these parameters as required parameters for the endpoint e.g.

Query Parameters

You can think of this parameter as an optional parameter which we can use to filter payloads. Some common query parameters are: page/size/sort.

SETUP: FASTAPI

Disclaimer - Inside this repository you will find simple endpoint examples

(I am assuming you already have an active Python dev environment w/ at least Python 3.10.6)

  • Clone this repository
  • Open the cloned repository in VSCode or you preferred IDE.
  • View setup.md for installation guide

Mac: python3 script-file.py

Windows: python script-file.py

What got installed? FastAPI - A Web Framework for quickly creating APIs, Unicorn - an ASGI server

CREATING YOUR FIRST ENDPOINT

  • ⚠️ ATTENTION ⚠️ If you get lost at any point or would like to jump ahead you can view the Resource folder inside the cloned repository. It will have a completed copy of what we're about done to in this tutorial.

From your IDE create a file called tutorial.py.

Running the server

Mac: python3 run.py

Windows: python run.py

TESTING YOUR FIRST ENDPOINT

Open your web browser and navigate to: localhost:8000/docs. If you followed the steps correctly you will notice the "read root" endpoint. Now let's test it.

CREATING ENDPOINTS