Project created for realize Challenge Backend Products Api, project which allows manipulate and relate products and categories.
-
Mandatory requirements
1.User should be able of create, read, update and delete products.
2.User should be able of create, read, update and delete categories.
3.A product must be related to a category.
4.A category must be related to one or more products.
5.Queries must return a maximum of 10 items by request.
6.The product query should be able to return a specific product or all of them.
7.The category query must be able to return a specific category or all.
Product output:
[
{
"id": 1,
"name": "Nike Shoes for Man",
"description": "Nike Shoes",
"price": 199.99,
"category": {
"id": 1,
"name": "Shoes"
}
},
{
"id": 2,
"name": "Amanda Waller Shirt Men",
"description": "New awesome shirt",
"price": 32.49,
"category": {
"id": 2,
"name": "Shirts"
}
}
]
Category output:
[
{
"id": 1,
"name": "Shoes"
},
{
"id": 2,
"name": "Shirts"
}
]
Follow list with any frameworks and libs used in building of the application.
- FastApi
- Uvicorn
- SQLAlchemy
- Psycopg2-Binary
- FastApi-Pagination
- Pydantic
To build and run the application, you need to install the dependencies below:
- Steps for configuration
-
Clone application
git clone https://git@github.com/thatavieira/backend_challenge_products_api.git
-
Creating and Initializing Virtual Enviroment
python3 -m venv .venv && source venv/bin/activate
-
Installing Packages
python3 -m pip install -r requirements.txt
-
Initializing API
python3 main.py
Ps.: You must have PostgreSQL installed, if not you can use Docker as below.
- Docker - Optional
- If you want to run the application in docker, configure the file docker-compose and after the command
docker-compose up --build -d
2.Configure the environment variables for containers in docker-compose.yml
file:
version: "3.7"
services:
app:
build: .
container_name: app
command: uvicorn src.api:app --host 0.0.0.0
ports:
- 8000:8000
depends_on:
- "db"
db:
image: postgres:12.1-alpine
container_name: db
ports:
- 5432:5432
environment:
- POSTGRES_USER=${POSTGRES_USER}
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
- POSTGRES_DB=${POSTGRES_DB}
API developed with FastApi, framework focused on API development, modern, fast, simple and robust. Using Uvicorn to implement web server. FastApi-Pagination used to limit the amount of information for each request, so avoiding data overload for query. SQLAlchemy an ORM created with Python which can access a database using Python instead of SQL. Pyscopg2 used to connect to PostgreSQL database. Pydantic a library that analyzes and validates data returning easy-to-understand answers.
Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply opena an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request