Welcome to the Symfony E-commerce API! This project provides endpoints for user management, product management, cart management, and order processing. It's built with Symfony and uses JWT for authentication.
- Installation
- Configuration
- Running the Application
- API Endpoints
- Roles and Permissions
- Postman Collection
This API allows you to manage users, products, carts, and orders for an e-commerce platform. It includes features like:
- User registration, login, and profile management
- CRUD operations for products
- Cart management (add, remove, validate, and pay for items)
- Order management and history tracking
-
Clone the repository:
git clone https://github.com/Yasser5711/Symfony-E-commerce-API.git cd Symfony-E-commerce-API -
Install dependencies:
composer install
-
Set up environment variables: Copy the
.envfile and set your environment variables.cp .env.example .env
-
Generate the JWT keys:
mkdir -p config/jwt openssl genpkey -algorithm RSA -out config/jwt/private.pem -aes256 openssl pkey -in config/jwt/private.pem -out config/jwt/public.pem -pubout
-
Database setup: Update your
.envfile with your database credentials and then run the migrations.php bin/console doctrine:database:create php bin/console doctrine:migrations:migrate
- JWT_SECRET_KEY: Set this value in your
.envfile. - Database: Configure your database connection in the
.envfile.
-
Start the Symfony server:
symfony server:start
-
Access the application: The application should now be running at
http://127.0.0.1:8000.
- Register:
POST /api/register - Login:
POST /api/login - Logout:
POST /api/logout - Get User:
GET /api/get-user(Authenticated) - Update User:
POST /api/get-user(Authenticated) - Delete User:
DELETE /api/get-user(Authenticated) - Get All Users:
GET /api/get-all-users(Admin) - Update User Role:
POST /api/update-user-role(Admin)
- Get All Products:
GET /api/products - Get Product:
GET /api/products/{id} - Add Product:
POST /api/products(Admin) - Update Product:
PUT /api/products/{id}(Admin) - Delete Product:
DELETE /api/products/{id}(Admin)
- Add to Cart:
POST /api/carts(Authenticated) - Get User Cart:
GET /api/carts(Authenticated) - Validate Cart:
PATCH /api/carts/validate(Authenticated) - Pay Cart:
PATCH /api/carts/pay/{id}(Authenticated) - Remove Product from Cart:
DELETE /api/carts/{id}(Authenticated)
- Get All Orders:
GET /api/orders(Authenticated) - Get Order:
GET /api/orders/{id}(Authenticated) - Cancel Order:
DELETE /api/orders/{id}(Authenticated) - Order History:
GET /api/history(Authenticated)
- Admin: Can manage all users, products, and has access to all routes.
- User: Can manage their own profile, cart, and orders. Can view products.
A Postman collection is available to test the API endpoints. Import the provided collection file into Postman.
To use the Postman collection:
- Open Postman.
- Click on the Import button.
- Select the
postman_collection.jsonfile from the repository and import it.
You can find the Postman collection file here: postman_collection.json