This is a simple greetings API. It sets an initial greeting of "hello world", but also gives the user the option to add additional greetings.
The Greetings API has four routes:
- GET
/
- redirects to OpenAPI/Swagger interactive API documentation (/docs
)/greetings/
- returns a JSON response list of greetings from the database/greetings/{greeting_id}
- returns a JSON response of greeting, based on the greeting's id ({greeting_id}
) in the database.{"message":"hello world","id":1}
- POST
/greetings/
- creates a greeting if a matching one does not already exist. Expects a JSON payload of{"message":"<greeting message>"}
The API can be run via Docker Compose:
-
Docker compose
docker-compose up -d
The API path for retrieving greetings is /greetings/
. One can visit in the browser http://localhost:8000/greetings/
or via curl command curl http://localhost:8000/greetings/
This returns a JSON array of existing greetings stored in the database.
Other options for using the API include:
curl -X 'POST' \
'http://localhost:8000/greetings/' \
-H 'Content-Type: application/json' \
-d '{
"message": "howdy"
}'
Example for getting the greeting with id=1
curl -X 'GET' 'http://localhost:8000/greetings/1'
The Greetings API uses FastAPI, which includes interactive API documentation (provided by Swagger UI). Open in the browser by visiting http://localhost:8000/docs (or get redirected from http://localhost:8000/)