Table of Contents
FastOrders API is a RESTful API that handles order management. This backend project is a FastAPI-based template designed to serve as a robust, reliable, and RESTful API backend. It is crucial for facilitating user authentication, real-time monitoring, data processing, and an advanced alerting system. By leveraging the principles of RESTful architecture, this API ensures standardized communication and a scalable, maintainable infrastructure for the associated mobile application. This project is not only vital for the functionality it provides but also for ensuring the scalability and maintainability of the overall solution.
This project is built using a suite of modern, powerful technologies and frameworks to ensure high performance, ease of development, and robustness:
The system is composed of the following main components, each playing a crucial role in providing a scalable, maintainable, and robust application:
- FastAPI Backend: Serves as the core of the RESTful API, handling incoming HTTP requests, processing data, and sending responses. It's designed for high performance and encourages standard API development practices.
- PostgreSQL: PostgreSQL is used for structured relational data storage.
- JWT Authentication: Implements secure authentication mechanisms using JSON Web Tokens (JWT), ensuring secure access to the API.
This project adheres to RESTful design principles, ensuring an intuitive and standard approach to API development. This design facilitates easy integration, scalability, and interaction with various clients, including web and mobile applications. The API provides clear, resource-oriented URLs, uses HTTP response codes to indicate API errors, and employs JWT for secure, stateless authentication.
-
Clone the repository
git clone https://github.com/jpcadena/fastorders-api.git
-
Change the directory to root project
cd fastorders-api -
Create a virtual environment named .venv in the working directory
uv venv
-
Activate environment in Windows
.\venv\Scripts\activate
-
Activate environment in macOS or Linux
source venv/bin/activate -
Update project's environment by syncing all of its dependencies and installing them
uv sync
-
Execute with console
python main.py
-
Running tests:
To run all tests, you can run the following command in the root directory of the project:
pytest . pytest tests/ --cov=src --cov-report=term-missing -
Running a specific test:
If you want to run a specific test, you can do so by specifying the file and test name. For example, the following command will only run the
test_get_userstest in thetest_main.pyfile:pytest tests/test_main.py::test_get_users
-
Understanding test results:
Pytest will provide a summary of the test results in the console. It will tell you how many tests passed and how many failed. For each failed test, Pytest will provide a detailed error message that can help you identify what went wrong.
-
Writing new tests:
When you add new features to the application, you should also write corresponding test cases. Each test case should be a function that starts with the word 'test.' Inside the function, you can use
assertstatements to check that your code is working as expected. For example:from src.infrastructure.models import User from src.infrastructure.services.user_service import add_user def test_add_user(): user: User = add_user("testuser", "testpass") assert user.name == "testuser" assert user.password == "testpass"
This function tests that the
add_userfunction correctly creates a new user with the given name and password.
Remember to update your tests whenever you update your code. Maintaining a comprehensive test suite will help ensure the reliability and robustness of your application.
Please read our contributing guide for details on our code of conduct, and the process for submitting pull requests to us.
For security considerations and best practices, please refer to our Security Guide for a detailed guide.
We enforce a code of conduct for all maintainers and contributors. Please read our Code of Conduct to understand the expectations before making any contributions.
Distributed under the MIT License. See LICENSE for more information.
