An API for inspirational quotes, built with FastAPI and SQLAlchemy.
With this API, you can fetch quotes, add them, update them and delete them.
sudo docker build -t inspo_quotes_api ./
sudo docker run -p 80:80 inspo_quotes_api
This program requires Python 3.10.
python3 -m venv venv
source ./venv/bin/activate
pip install -r requirements.txt
python3 init_db.py
To run this in a dev environment:
source ./venv/bin/activate
uvicorn main:app --reload
The default response format for all the GET
requests is plain text, but you can provide another HTTP Accept
header to modify the response format.
Available Accept
headers:
text/plain
- Plain text response (default)application/json
- JSON response
Fetch a random inspirational quote.
$ curl 127.0.0.1:8000/
{
"id": 3,
"quote": "I have not failed. I've just found 10,000 ways that won't work.",
"status": 200
}
Fetch a specific quote.
$ curl 127.0.0.1:8000/q/5
{
"id": 5,
"quote": "Everything you can imagine is real.",
"status": 200
}
Add a new quote. You will get the ID of the quote through the JSON response. The max quote length is 100 characters.
$ curl 127.0.0.1:8000/add -X POST -H "Content-Type: application/json" -d '{ "text": "You miss all the shots you don'\''t take." }'
{
"id": 10,
"status": 200
}
Update a quote by ID with new text.
$ curl 127.0.0.1:8000/update -X POST -H "Content-Type: application/json" -d '{ "id": 6, "text": "When you have a dream, you'\''ve got to grab it and never let go." }'
{
"status": 200
}
Delete a quote by ID.
$ curl -X POST 127.0.0.1:8000/delete -H "Content-Type: application/json" -d '{ "id": 7 }'
{
"status": 200
}
This program is licensed under the MIT license.