Title here
Summary here
I have Python 3.12.2 installed on Mac.
$ python3 -V
We can use Poetry for Python packaging and dependency management. We need to install pipx
first.
brew install pipx
pipx ensurepath
Install poetry:
pipx install poetry
Check version:
$ poetry --version
Poetry (version 1.8.2)
Open a new terminal and run:
poetry completions bash >> ~/.bash_completion
For formatting source code:
$ pip install black
For testing:
$ pip install pytest
Install FastAPI framework:
pip install fastapi
An asynchronous web server:
pip install uvicorn
To hit the API from the terminal:
pip install httpie
A synchronous web client package:
pip install requests
A synchronous/asynchronous web client package
pip install httpx
We can now check our development setup. Create a hi.py
file:
from fastapi import FastAPI
api = FastAPI()
@api.get("/")
def greet():
return {"message": "Hello FastAPI"}
$ uvicorn hi:api --reload
View the response in the browser at: http://127.0.0.1:8000/
Use http in the terminal:
$ http http://127.0.0.1:8000/
HTTP/1.1 200 OK
content-length: 27
content-type: application/json
date: Sun, 31 Mar 2024 15:32:48 GMT
server: uvicorn
{
"message": "Hello FastAPI"
}
$ http -b http://127.0.0.1:8000/
{
"message": "Hello FastAPI"
}
$ http -v http://127.0.0.1:8000/
GET / HTTP/1.1
Accept: */*
Accept-Encoding: gzip, deflate
Connection: keep-alive
Host: 127.0.0.1:8000
User-Agent: HTTPie/3.2.2
HTTP/1.1 200 OK
content-length: 27
content-type: application/json
date: Sun, 31 Mar 2024 15:33:52 GMT
server: uvicorn
{
"message": "Hello FastAPI"
}