In this project, we will build a RESTful API that generates random quotes. The quotes will be stored in a database and the API will expose endpoints for CRUD operations (Create, Read, Update, Delete).
Here are some additional features we can add:
- Filter quotes by author name or keyword in the text
- Allow users to rate quotes and retrieve a list of top-rated quotes
- Add user authentication and authorization to restrict access to quote creation, deletion, and updating
- Python
- FastAPI
- SQLAlchemy
- SQLite
- Retrieve a random quote
GET /quotes/random
Returns a single random quote:
{
"id": 1,
"text": "The greatest glory in living lies not in never falling, but in rising every time we fall.",
"author": "Nelson Mandela"
}
2.Search in Quotes:
GET /quotes?q=someone
Response:
[
{
"id": 5,
"text": "Dignity will only happen when you realize that having someone in your life doesn’t validate your worth.",
"author": "Shannon L. Alder"
}
]
- Retrieve a list of all quotes
GET /quotes
Returns a list of all quotes in the system:
[
{
"id": 1,
"text": "The greatest glory in living lies not in never falling, but in rising every time we fall.",
"author": "Nelson Mandela"
},
{
"id": 2,
"text": "If you look at what you have in life, you'll always have more. If you look at what you don't have in life, you'll never have enough.",
"author": "Oprah Winfrey"
}
]
- Add a new quote
POST /quotes
Adds a new quote to the system. The request body should include a JSON object with the following properties:
text
(string, required): the text of the quoteauthor
(string, required): the author of the quote
{
"text": "The best way to predict the future is to invent it.",
"author": "Alan Kay"
}
- Update an existing quote
PUT /quotes/{quote_id}
Updates an existing quote with the given quote_id. The request body should include a JSON object with the following properties:
text
(string): the new text of the quoteauthor
(string): the new author of the quote
{
"text": "The only way to do great work is to love what you do.",
"author": "Steve Jobs"
}
- Delete a quote
DELETE /quotes/{quote_id}
Deletes the quote with the given quote_id
.
Copyright 2023, Max Base