Acebots-AI / my-tiny-service

0 stars 1 forks source link

Add endpoint that returns current timestamp #24

Closed artmoskvin closed 4 months ago

artmoskvin commented 4 months ago

The timestamp should have the ISO format

acebots-ai[bot] commented 4 months ago

Based on the project outline, here's a plan for implementing an endpoint that returns the current timestamp in ISO format:

  1. Create a New Endpoint in the Root Router:

    • Add a new function in my_tiny_service/api/routers/root.py that handles requests to a new endpoint, e.g., /timestamp.
    • This function should return the current timestamp in ISO format.
  2. Utilize Python's datetime Module:

    • In the new endpoint function, use Python's datetime module to get the current date and time.
    • Format the current date and time in ISO 8601 format using the isoformat() method.
  3. Update the API Router:

    • Register the new endpoint function with the FastAPI router in my_tiny_service/api/routers/root.py by adding a route with an appropriate path, e.g., /timestamp.
  4. Test the New Endpoint:

    • Add a new test function in tests/test_api.py to ensure the new /timestamp endpoint returns the correct format and status code.
    • Use the starlette.testclient.TestClient to make a request to the new endpoint and verify the response.
  5. Documentation and Cleanup:

    • Ensure that the new endpoint is properly documented within the code, explaining its purpose and usage.
    • Review the implementation for any potential refactoring or optimization opportunities.

This plan outlines the steps needed to add a new endpoint to the existing FastAPI project, ensuring it returns the current timestamp in ISO format.

artmoskvin commented 4 months ago

@acedev-ai looks good, please proceed

acebots-ai[bot] commented 4 months ago

I've successfully implemented the new endpoint and created a pull request:

This pull request adds a new endpoint /timestamp to the API that returns the current timestamp in ISO format. It also includes a test to ensure the endpoint behaves as expected.