A RESTful API for an e-commerce platform that allows customers browse through products, add products to their shopping cart, place orders for those products and purchase them. The API comes with endpoints for managing orders, product reviews, authentication and authorization. It also supports pagination, filtering, etc.
Some features include
- JWT Authentication and authorization
- Optimized database queries
- Interactive Swagger documentation
- Braintree payment integration
- Debug toolbar and more...
- Python 3.10
- Django 4.1.2
- Django Rest Framework 3.14.0
- PostgreSQL 12
Clone the repository using the git command
git clone https://github.com/klvxn/ecommerce-API
Navigate into the project's root directory
cd ecommerce-API
Build the docker images
docker-compose build
Run the docker containers
docker-compose up
The API will be ready at: http://localhost:8000/
Access the documentation at: http://localhost:8000/swagger/
Here are some of the endpoints.
Assuming the local server is running at http://localhost:8000
Create a user account
POST http://localhost:8000/api/v1/customers/
REQUEST BODY
{
"email": "[email protected]",
"first_name": "Django",
"last_name": "Admin",
"date_of_birth": "2022-10-15",
"password": "djangorest",
"password2": "djangorest"
}
Create access token
POST http://localhost:8000/auth/token/
REQUEST BODY
{
"email": "[email protected]",
"password": "djangorest"
}
Logout user
POST http://localhost:8000/auth/logout/
Refresh access token
POST http://localhost:8000/auth/token/refresh/
REQUEST BODY
{"refresh": "your_refresh_token"}
Retrieve all products or a single product
GET http://localhost:8000/api/v1/products/
GET http://localhost:8000/api/v1/products/{id}
Add a product with Id to cart
POST http://localhost:8000/api/v1/products/{Id}/add/
REQUEST BODY
{"quantity": 3}
Remove a product from cart
DELETE http://localhost:8000/api/v1/products/{Id}/delete/
Retrieve items in shopping cart
GET http://localhost:8000/api/v1/shopping-cart/
Create an order from user's cart items
POST http://localhost:8000/api/v1/shopping-cart/
REQUEST BODY
{"action": "create_order"}
Update an item in cart
PUT http://localhost:8000/api/v1/shopping-cart/
REQUEST BODY
{"product_name": 7}
Remove an item from cart
if request body is empty, cart will be cleared.
DELETE http://localhost:8000/api/v1/cart/
REQUEST BODY
{"product_name": ""}
Retrieve all orders or a single order
GET http://localhost:8000/api/v1/orders/
GET http://localhost:8000/api/v1/orders/{id}
Update an order with a new address
PUT http://localhost:8000/api/v1/orders/{id}/
REQUEST BODY
{
"street_address": "Somewhere you live",
"postal_code": 012345,
"city": "New Genius",
"state": "Your state",
"country": "Your country",
}
Delete an order
DELETE http://localhost:8000/api/v1/orders/{id}/
Retrieve the template to input payment method details
GET http://localhost:8000/api/v1/checkout/order/{id}/
Process payment for an order
POST http://localhost:8000/api/v1/checkout/order/{id}/make-payment/
REQUEST BODY
{
5555 5555 5555 4444
02/24
}
Paid orders are exported to a csv file. If you get an error (e.g. processor declined) while testing payments, check the Braintree docs
http://localhost:8000/api/v1/openapi/
The documentation for the API and the rest of it's endpoints are available at:
http://localhost:8000/swagger/
This project is licensed under the MIT License - see the LICENSE file for details.
If you have any questions or issues with the API, please contact me at [email protected].