This documentation outlines the API endpoints, request/response formats, authentication/authorization, error handling, and usage examples for our backend services.
The base URL for all API endpoints is: https://example.com/api
- Endpoint: POST /auth/signup
- Description: Registers a new user with the specified details.
- Request Body:
{
"fullName": "John Doe",
"email": "johndoe@example.com",
"password": "securepassword",
"role": "seller",
"region": "North America"
}
- Response (Success - 201 Created):
{
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
}
- Response (Error - 400 Bad Request):
{
"message": "Email already exists. Please try a new Email"
}
- Endpoint: POST /auth/login
- Description: Logs in a user with valid credentials.
- Request Body:
{
"email": "johndoe@example.com",
"password": "securepassword"
}
- Response (Success - 200 OK):
{
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
}
- Response (Error - 400 Bad Request):
{
"message": "Invalid Credentials!"
}
- Endpoint: POST /auth/logout
- Description: Logs out the currently authenticated user.
- Response (Success - 200 OK):
{
"message": "Logout successful"
}
#User Endpoints
- Endpoint: GET /users
- Description: Retrieves a list of all users (admin only).
- Endpoint: GET /users/:id
- Description: Retrieves a specific user by their ID.
- Endpoint: PUT /users/:id
- Description: Updates a user's profile information.
- Endpoint: DELETE /users/:id
- Description: Deletes a user's account.
#Product Endpoints
- Endpoint: GET /products
- Description: Retrieves a list of all products.
- Endpoint: GET /products/:id
- Description: Retrieves a specific product by its ID.
- Endpoint: POST /products
- Description: Adds a new product to the database (seller only).
- Endpoint: PUT /products/:id
- Description: Updates a product's information (seller only).
- Endpoint: DELETE /products/:id
- Description: Deletes a product from the database (seller only).
- Description: The request is invalid or missing required parameters.
- Description: Authentication credentials are missing or invalid.
- Description: The user is not authorized to access the requested resource.
- Description: The requested resource was not found.
- Description: An unexpected server error occurred.
Here are some usage examples in JavaScript using Axios:
axios.post('https://example.com/api/auth/signup', {
fullName: 'John Doe',
email: 'johndoe@example.com',
password: 'securepassword',
role: 'seller',
region: 'North America'
})
.then(response => {
console.log(response.data.token);
})
.catch(error => {
console.error(error.response.data.message);
});
axios.post('https://example.com/api/auth/login', {
email: 'johndoe@example.com',
password: 'securepassword'
})
.then(response => {
console.log(response.data.token);
})
.catch(error => {
console.error(error.response.data.message);
});
axios.get('https://example.com/api/users')
.then(response => {
console.log(response.data);
})
.catch(error => {
console.error(error.response.data.message);
});
Client: React, Redux, TailwindCSS
Server: Node, Express, MongoDB
Clone the project
git clone https://github.com/Code-Gale/simplicy_backend
Go to the project directory
cd simplicy
Install dependencies
npm install
Start the server
nodemon app
Signup(POST) - /api/auth/signup
Login(POST) - /api/auth/login
Logout(POST) - /api/auth/logout
All Users(GET) - /api/users/
UserById(GET) - /api/users/:id
Update User(PUT) - /api/users/:id
Delete User(DELETE) - /api/users/:id
All Products(GET) - /api/products/
ProductById(GET) - /api/products/:id
ProductsBySeller(GET) - /api/products/:id/products
New Product(POST)(Sellers only) - /api/products/newProducts
Update Product(PUT)(Sellers only) - /api/products/:id
Delete Product(DELETE)(Sellers only) - /api/products/:id
To be integrated into Simplicy Frontend