Giter Club home page Giter Club logo

fastapi's Issues

Feature Request: Add Background Task Processing Endpoint

Description

As a user of the FastAPI application, I would like to have the ability to trigger background tasks via a new API endpoint /process. This endpoint should execute a simple background task, such as running a command to sleep for a specified duration, and return the ID of the started task. Additionally, users should be able to check the status of background tasks using a polling approach by implementing a new endpoint /getresult which retrieves the task status by ID.

Requirements

  • Create a new API endpoint /process to trigger background tasks.
  • When accessed, the /process endpoint should initiate a background task.
  • The background task should involve executing a command to sleep for a specified duration, e.g., sleep 15.
  • Upon successful initiation of the background task, the endpoint should return the ID of the started task.
  • Implement a new API endpoint /getresult to retrieve the status of a background task by its ID.
  • Users should be able to poll the /getresult endpoint to check the status of a background task.

Additional Notes

  • Ensure proper error handling and informative responses for both endpoints.
  • Consider implementing task management features such as cancellation or status updates.
  • Maintain consistency with existing API design and adhere to best practices for RESTful APIs.
  • Documentation updates may be required to reflect the new endpoints and their usage.

Acceptance Criteria

  • The /process endpoint successfully triggers a background task and returns the ID of the started task.
  • The background task executes the specified command, e.g., sleep 15.
  • The /getresult endpoint retrieves the status of a background task by its ID.
  • Users can effectively utilize polling to check the status of background tasks.

References

Priority

Medium

Labels

  • enhancement
  • API
  • background-task

Implement CRUD API endpoints for in-memory user database

Add the necessary code and functionality to implement CRUD (Create, Read, Update, Delete) API endpoints for managing a user database in the FastAPI application. The user database will be an in-memory database that stores users' data: username, email, and number of tasks. Additional checks and validations should be implemented as specified below.

Requirements:

  • Users should be represented using a Python class or data model that includes the following fields:

    • Username (string)
    • Email (string, validated as a proper email format)
    • Number of tasks (integer, validated to ensure it's not a negative number)
  • The API should support the following endpoints:

    • GET /users/{user_id}: Retrieve a specific user by their ID.
    • POST /users: Create a new user.
    • PUT /users/{user_id}: Update an existing user by their ID.
    • DELETE /users/{user_id}: Delete a user by their ID.
  • The API endpoints should interact with an in-memory database that holds the list of users.

  • Proper error handling should be implemented for cases such as invalid user IDs, non-existent users, incorrect email formats, or negative numbers of tasks.

  • The code should be well-structured, readable, and follow best practices for FastAPI development.

Additional Information:

  • The baseline FastAPI application is provided in the app/main.py file.
  • Make sure that the code is covered with unit tests.
  • Run the code and test the API endpoints to validate the functionality.

Acceptance Criteria:

  • The FastAPI application should include the implemented CRUD API endpoints for managing the user database.
  • The endpoints should have the necessary checks and validations in place.
  • The application should utilize an in-memory database to store and retrieve user data.
  • Error handling should be implemented for invalid requests or scenarios.
  • The code should be well-structured and follow best practices.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.