This comprehensive guide serves as your one-stop resource for exploring and utilizing the Server-Store API effectively. Whether you're a seasoned developer or just getting started, this documentation equips you with the knowledge to integrate the API seamlessly into your projects.
What is Server-Store?
Server-Store is a robust API designed to simplify the management of products, users, and authentication functionalities within an e-commerce application.
Structure
SERVIDOR-STORE
├── src
│ ├── configs
│ │ ├── utils
│ │ └── server.js
│ ├── controllers
│ │ ├── AllProductsController.js
│ │ ├── ProductController.js
│ │ ├── SessionsController.js
│ │ ├── TagsController.js
│ │ ├── UserAvatarController.js
│ │ └── UserController.js
│ ├── database
│ │ ├── knex
│ │ │ ├── migrations
│ │ │ │ ├── 20240320202727_createProducts.js
│ │ │ │ ├── 20240321003608_createTags.js
│ │ │ │ └── 20240321004040_createLinks.js
│ │ │ └── index.js
│ │ ├── sqlite
│ │ │ ├── migrations
│ │ │ │ ├── createUsers.js
│ │ │ │ └── index.js
│ │ │ └── index.js
│ │ └── database.db
│ ├── middlewares
│ │ └── ensureAuthenticated.js
│ ├── providers
│ │ └── DiskStorage.js
│ ├── repositories
│ │ ├── UserRepository.js
│ │ └── UserRepositoryInMemory.js
│ ├── routes
│ │ ├── allProducts.routes.js
│ │ ├── index.js
│ │ ├── products.routes.js
│ │ ├── sessions.routes.js
│ │ ├── tags.routes.js
│ │ └── users.routes.js
│ ├── services
│ │ ├── UserCreateService.js
│ │ └── userCreateService.spec.js
│ ├── utils
│ │ └── AppError.js
│ └── server.js
├── tmp
│ ├── uploads
│ │ └── ...
│ └── uploads
├── knexfile.js
├── package-lock.json
├── package.json
└── README.md
Welcome to the Server-Store API documentation. This API allows for the management of products, users, and authentication for an online store.
The base URL for all API endpoints is:
https://localhost:3333
The API utilizes JWT (JSON Web Tokens) based authentication to ensure the security of operations. To access protected endpoints, it is necessary to include the JWT token in the request authorization header.
POST /register
Registers a new user in the API.
name
: User's name (string)email
: User's email address (string)password
: User's password (string)
{
"name": "John Doe",
"email": "john@example.com",
"password": "password123"
}
Status: 201 Created
{
"message": "User created successfully"
}
Status: 400 Bad Request
{
"error": "Email already in use"
}
POST /login
Authenticates a user in the API and returns a JWT token for access to protected endpoints.
email
: User's email address (string)password
: User's password (string)
{
"email": "john@example.com",
"password": "password123"
}
Status: 200 OK
{
"user": {
"id": 1,
"name": "John Doe",
"email": "john@example.com"
},
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
}
Status: 401 Unauthorized
{
"error": "Email or password invalid"
}
The Server-Store API offers the following resources:
- User Registration:
POST /register
- User Authentication:
POST /login
- List Products:
GET /products
- Product Details:
GET /products/:id
- Create Product:
POST /products
- Update Product:
PUT /products/:id
- Delete Product:
DELETE /products/:id
-
User Registration:
POST /register
- Registers a new user in the API.
name
: User's name (string)email
: User's email address (string)password
: User's password (string)
{ "name": "John Doe", "email": "john@example.com", "password": "password123" }
Status: 201 Created
{ "message": "User created successfully" }
Status: 400 Bad Request
{ "error": "Email already in use" }
-
User Authentication:
POST /login
- Authenticates a user in the API and returns a JWT token for access to protected endpoints.
email
: User's email address (string)password
: User's password (string)
{ "email": "john@example.com", "password": "password123" }
Status: 200 OK
{ "user": { "id": 1, "name": "John Doe", "email": "john@example.com" }, "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..." }
Status: 401 Unauthorized
{ "error": "Email or password invalid" }
-
List All Products:
GET /products
- Returns a list of all products available in the store, including their details, tags, and associated links.
None.
GET /products
Status: 200 OK
[ { "id": 1, "title": "Product 1", "description": "Description of product 1", "price": 99.99, "productIMG": "product1.jpg", "category": "Category 1", "urlProduct": "http://example.com/product1", "tags": [ { "id": 1, "name": "Tag 1" }, { "id": 2, "name": "Tag 2" } ] }, { "id": 2, "title": "Product 2", "description": "Description of product 2", "price": 149.99, "productIMG": "product2.jpg", "category": "Category 2", "urlProduct": "http://example.com/product2", "tags": [ { "id": 3, "name": "Tag 3" }, { "id": 4, "name": "Tag 4" } ] } ]
-
Product Details:
GET /products/:id
- Returns the details of a specific product based on the provided ID, including its details, tags, and associated links.
id
: Product ID (integer)
GET /products/1
Status: 200 OK
{ "id": 1, "title": "Product 1", "description": "Description of product 1", "price": 99.99, "productIMG": "product1.jpg", "category": "Category 1", "urlProduct": "http://example.com/product1", "tags": [ { "id": 1, "name": "Tag 1" }, { "id": 2, "name": "Tag 2" } ] }
Status: 404 Not Found
{ "error": "Product not found" }
-
Create Product:
POST /products
- Creates a new product in the store.
title
: Product title (string)description
: Product description (string)price
: Product price (number)urlProduct
: Product URL (string)productIMG
: Product image (file)category
: Product category (string)tags
: Array of tags associated with the product (array of strings)
{ "title": "New Product", "description": "Description of the new product", "price": 199.99, "urlProduct": "http://example.com/new-product", "productIMG": (product image), "category": "Category", "tags": ["Tag 1", "Tag 2"] }
Status: 201 Created
{ "message": "Product created successfully" }
-
Update Product:
PUT /products/:id
- Updates the information of an existing product in the store based on the provided ID.
id
: Product ID (integer)title
: Product title (string, optional)description
: Product description (string, optional)price
: Product price (number, optional)urlProduct
: Product URL (string, optional)productIMG
: Product image (file, optional)category
: Product category (string, optional)tags
: Array of tags associated with the product (array of strings, optional)
{ "title": "New product", "description": "New description of the product", "price": 249.99, "urlProduct": "https://www.example.com", "tags": ["Tag 1", "Tag 2", "Tag 3"] }
Status: 200 OK
{ "message": "Product updated successfully" }
Status: 404 Not Found
{ "error": "Product not found" }
-
Delete Product:
DELETE /products/:id
- Deletes a product from the store based on the provided ID.
id
: Product ID (integer)
DELETE /products/1
Status: 200 OK
{ "message": "Product deleted successfully" }
Status: 404 Not Found
{ "error": "Product not found" }