Title here
Summary here
I have Python 3.12.2 installed on Mac.
$ python3 -VWe can use Poetry for Python packaging and dependency management. We need to install pipx first.
brew install pipx
pipx ensurepathInstall poetry:
pipx install poetryCheck version:
$ poetry --versionPoetry (version 1.8.2)Open a new terminal and run:
poetry completions bash >> ~/.bash_completionFor formatting source code:
$ pip install blackFor testing:
$ pip install pytestInstall FastAPI framework:
pip install fastapiAn asynchronous web server:
pip install uvicornTo hit the API from the terminal:
pip install httpieA synchronous web client package:
pip install requestsA synchronous/asynchronous web client package
pip install httpxWe 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 --reloadView 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"
}