Skip to content

Ilustra API for managing the word of the day using fastapi and pymongo. The app provides endpoints for retrieving, adding, updating, and deleting word

Notifications You must be signed in to change notification settings

AlexOliveiraaDev/api-ilustra-python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Ilustra API

Ilustra Python FastAPI MongoDB Pytest

🚀 Ilustra API for managing the word of the day using fastapi and pymongo. The app provides endpoints for retrieving, adding, updating, and deleting words.

In Development Badge

Features

  • 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 🗑️

Setup 🛠️

Prerequisites

  • Python 3.8+
  • MongoDB (or a running instance of MongoDB Atlas)

Installation

  1. Clone this repository:

    git clone https://github.com/AlexOliveiraaDev/api-ilustra-python.git
    cd api-ilustra-python
  2. Install dependencies:

    pip install -r requirements.txt
  3. Set up your environment variables:

    • Create a .env file in the root directory.
    • Add the following line to the .env file:
      API_URL=mongodb://your-mongo-url
  4. Run the application:

    fastapi dev app.py

API Endpoints 📚

GET /getDayWord

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"
    }
  }
}

POST /addDayWord

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"
}

PUT /updateDayWord/{word_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 /deleteDayWord/{word_id}

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.

Testing 🧪

Running Tests

To run the tests, use pytest:

pytest

The 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.

Example Test for GET /getDayWord

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

Acknowledgments 🙏

  • FastAPI: Web framework used for building the API.
  • PyMongo: MongoDB driver for Python.
  • pytest: Framework used for testing.

Made with ❤️ by Alex Oliveira

About

Ilustra API for managing the word of the day using fastapi and pymongo. The app provides endpoints for retrieving, adding, updating, and deleting word

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages