🚀 Ilustra API for managing the word of the day using fastapi and pymongo. The app provides endpoints for retrieving, adding, updating, and deleting words.
- GET
/getDayWord: Retrieve the current word of the day 📝 - POST
/addDayWord: Add a new word of the day ➕ - PUT
/updateDayWord/{word_id}: Update an existing word of the day 🔄 - DELETE
/deleteDayWord/{word_id}: Delete a word of the day 🗑️
- Python 3.8+
- MongoDB (or a running instance of MongoDB Atlas)
-
Clone this repository:
git clone https://github.com/AlexOliveiraaDev/api-ilustra-python.git cd api-ilustra-python -
Install dependencies:
pip install -r requirements.txt
-
Set up your environment variables:
- Create a
.envfile in the root directory. - Add the following line to the
.envfile:API_URL=mongodb://your-mongo-url
- Create a
-
Run the application:
fastapi dev app.py
Fetch the current word of the day.
Response:
{
"_id": "677f1aef8adee120d7892fd7",
"word": "Teste",
"images": [
"https://example.com",
"https://example.com",
"https://example.com",
"https://example.com",
"https://example.com"
],
"closeWords": [
"testes",
"palavra",
"outros"
],
"lastDate": {
"$date": {
"$numberLong": "1734318000000"
}
}
}Add a new word of the day. The request body should be in the following format:
Request Body:
{
"word": "NewWord",
"images": [
"https://newimage1.com",
"https://newimage2.com",
"https://newimage3.com",
"https://newimage4.com",
"https://newimage5.com"
],
"closeWords": [
"new",
"word",
"test"
],
"lastDate": {
"$date": {
"$numberLong": "1734318000000"
}
}
}Response:
{
"message": "Word added successfully",
"id": "your-inserted-id"
}Update an existing word of the day. Provide the word ID and updated data.
Request Body:
{
"word": "UpdatedWord",
"images": [
"https://updatedimage1.com",
"https://updatedimage2.com",
"https://updatedimage3.com",
"https://updatedimage4.com",
"https://updatedimage5.com"
],
"closeWords": [
"updated",
"word",
"example"
],
"lastDate": {
"$date": {
"$numberLong": "1734318000000"
}
}
}Response:
{
"message": "Word updated successfully"
}Delete the word of the day by its ID.
Response:
{
"message": "Word deleted successfully"
}Esse formato mantém o conteúdo organizado e pronto para ser compartilhado em Markdown.
To run the tests, use pytest:
pytestThe tests are defined in tests.py and test the following functionalities:
- Fetching the day word.
- Adding a new day word.
- Updating an existing day word.
- Deleting a day word.
def test_get_day_word(mock_db):
response = client.get("/getDayWord")
assert response.status_code == 200
data = response.json()
assert "word" in data
assert "images" in data
assert "closeWords" in data
assert "lastDate" in data- FastAPI: Web framework used for building the API.
- PyMongo: MongoDB driver for Python.
- pytest: Framework used for testing.
Made with ❤️ by Alex Oliveira