This project is a simple REST API built using Express and Node.js/Bun. It provides endpoints for managing items in a collection.
- SportsAppi
-
Clone the repository:
git clone https://github.com/yourusername/my-rest-api.git
-
Navigate to the project directory:
cd my-rest-api
-
Install bun:
npm install -g bun
-
Install the depencies:
bun install
-
Copy the
.env.example
to.env
and edit the environment variable.
To start the server, run:
bun start
The server will run on http://localhost:3000
by default.
All API endpoints are protected with authentication middleware. You must provide a valid API key using one of these methods:
- In the request body as
apiKey
- In the query parameters as
apiKey
- In the
Authorization
header
- Description: Retrieve all users
- Response: Array of user objects with fields: id_user, name, surname, address, zip, city, password, login
- Status Codes:
200 OK
: Successfully retrieved users500 Internal Server Error
: Failed to fetch users
- Description: Retrieve a specific user by ID
- Parameters:
id
(path): User ID
- Response: User object with fields: id_user, name, surname, address, zip, city, password, login
- Status Codes:
200 OK
: Successfully retrieved user404 Not Found
: User with specified ID not found500 Internal Server Error
: Failed to fetch user
- Description: Retrieve a user by login name (username)
- Parameters:
login
(path): User login/username
- Response: User object with limited fields: id_user, login, password
- Status Codes:
200 OK
: Successfully retrieved user404 Not Found
: User with specified login not found500 Internal Server Error
: Failed to fetch user
- Description: Create a new user
- Request Body:
name
: User's first namesurname
: User's last nameaddress
: User's addresszip
: ZIP/Postal codecity
: User's citypassword
: User's passwordlogin
: User's login/username
- Response:
message
: Success messageid
: ID of the created user
- Status Codes:
201 Created
: Successfully created user500 Internal Server Error
: Failed to create user
- Description: Update an existing user
- Parameters:
id
(path): User ID
- Request Body:
name
: User's first namesurname
: User's last nameaddress
: User's addresszip
: ZIP/Postal codecity
: User's citypassword
: User's passwordlogin
: User's login/username
- Response:
message
: Success message
- Status Codes:
200 OK
: Successfully updated user404 Not Found
: User with specified ID not found500 Internal Server Error
: Failed to update user
- Description: Delete a user
- Parameters:
id
(path): User ID
- Response:
message
: Success message
- Status Codes:
200 OK
: Successfully deleted user404 Not Found
: User with specified ID not found500 Internal Server Error
: Failed to delete user
- Description: Retrieve all products
- Response: Array of product objects with fields: reference, name, description, price, categories
- Status Codes:
200 OK
: Successfully retrieved products500 Internal Server Error
: Failed to fetch products
- Description: Retrieve a specific product by ID (reference)
- Parameters:
id
(path): Product reference
- Response: Product object with fields: reference, name, description, price, categories
- Status Codes:
200 OK
: Successfully retrieved product404 Not Found
: Product with specified reference not found500 Internal Server Error
: Failed to fetch product
- Description: Retrieve all images for a specific product
- Parameters:
id
(path): Product reference
- Response: Array of image objects
- Status Codes:
200 OK
: Successfully retrieved images500 Internal Server Error
: Failed to fetch product images
- Description: Add an image to a product
- Parameters:
id
(path): Product reference
- Request Body:
name
: Image name
- Response:
message
: Success message
- Status Codes:
201 Created
: Successfully added image400 Bad Request
: Missing required fields404 Not Found
: Product not found500 Internal Server Error
: Failed to add image
- Description: Retrieve all products from a specific category
- Parameters:
categoryId
(path): Category ID
- Response: Array of product objects with fields: reference, name, description, price, categories
- Status Codes:
200 OK
: Successfully retrieved products500 Internal Server Error
: Failed to fetch products
- Description: Create a new product
- Request Body:
reference
: Product reference (ID)name
: Product namedescription
: Product description (optional)price
: Product price
- Response:
message
: Success messagereference
: Product reference
- Status Codes:
201 Created
: Successfully created product400 Bad Request
: Missing required fields500 Internal Server Error
: Failed to create product
- Description: Update an existing product
- Parameters:
id
(path): Product reference
- Request Body:
name
: Product namedescription
: Product descriptionprice
: Product price
- Response:
message
: Success message
- Status Codes:
200 OK
: Successfully updated product404 Not Found
: Product not found500 Internal Server Error
: Failed to update product
- Description: Delete a product
- Parameters:
id
(path): Product reference
- Response:
message
: Success message
- Status Codes:
200 OK
: Successfully deleted product404 Not Found
: Product not found500 Internal Server Error
: Failed to delete product
- Description: Retrieve all product categories
- Response: Array of category objects with fields: id_category, name
- Status Codes:
200 OK
: Successfully retrieved categories500 Internal Server Error
: Failed to fetch categories
Note: The
categories
field returned in product endpoints is an array of objects withid_category
andname
fields.
- Description: Retrieve a specific order by ID
- Parameters:
id
(path): Order ID
- Response: Order object with fields: id_order, date_, delivery_address, prixtotal, status, id_user
- Status Codes:
200 OK
: Successfully retrieved order404 Not Found
: Order not found500 Internal Server Error
: Failed to fetch order
- Description: Retrieve all orders for a specific user
- Parameters:
userId
(path): User ID
- Response: Array of order objects
- Status Codes:
200 OK
: Successfully retrieved orders500 Internal Server Error
: Failed to fetch orders
- Description: Create a new order
- Request Body:
delivery_address
: Delivery addressprixtotal
: Total price of the orderid_user
: User IDproducts
: Array of objects withreference
andquantity
- Response:
message
: Success messageorderId
: ID of the created order
- Status Codes:
201 Created
: Successfully created order500 Internal Server Error
: Failed to create order
- Description: Update an existing order
- Parameters:
id
(path): Order ID
- Request Body:
delivery_address
: Delivery addressprixtotal
: Total price of the orderproducts
: Array of objects withreference
andquantity
- Response:
message
: Success message
- Status Codes:
200 OK
: Successfully updated order500 Internal Server Error
: Failed to update order
- Description: Update the status of an order
- Parameters:
id
(path): Order ID
- Request Body:
status
: New status value
- Response:
message
: Success message
- Status Codes:
200 OK
: Successfully updated order state404 Not Found
: Order not found500 Internal Server Error
: Failed to update order state
This project is licensed under the MIT License.