Ecommerce API Documentation

Getting started

API Documentation

This is a documentation for my Ecommerce API. This API is built to serve data to my other project: Ecommerce website in React (Front End).

The purpose of this API is to handle and control the requests between our MongoDB database and the Front End website.

API URL
https://ecommerce-api.ekerling.com/api


Products

GET /api/products

Retrieves all products.

Responses

200 - OK
500 - Internal Error


GET /api/products/{id}

Retrieves a specific product by its ID.

Responses

200 - OK
400 - Invalid Product ID
404 - Product not found
500 - Internal Server Error


POST /api/products

Creates a new product. The product data should be provided in the request body.

Responses

201 - OK, product added
404 - Product not found
500 - Internal Error


PUT /api/products/{id}

Updates a specific product by its ID. The updated product data should be provided in the request body.

DELETE /api/products/{id}

Deletes a specific product by its ID.

Messages

Messages are used for communication between users and the site owner.

GET /api/messages

Retrieves all messages in an array in JSON format.

Response

            
[
    {
        "_id": "6605622837a4902c3e5fa415",
        "name": "Name",
        "email": "email@ekerling.com",
        "message": "Message text here",
        "__v": 0
    },
    {
        "_id": "660570ca5439446e1e0b4772",
        "name": "Super Man",
        "email": "hey@email.com",
        "message": "Message text here",
        "__v": 0
    },
    {
        "_id": "66073908faa362a72b1c5645",
        "name": "John Smith",
        "email": "john@smith.com",
        "message": "Message text here",

        "__v": 0
    }
]
            
          

Response codes

200 - OK
404 - Product not found
500 - Internal Error


GET /api/messages/{id}

Retrieves a specific message by its ID.

Parameter {id}

Enter the ID for a specific message.

Response Example

{
    "_id": "66170ac311140c69e87b5ee9",
    "name": "Test name",
    "email": "name@email.com",
    "message": "This is a message",
    "createdAt": "2024-04-10T21:55:15.933Z",
    "updatedAt": "2024-04-10T21:55:15.933Z",
    "__v": 0
}

Response codes

200 - OK
404 - Product not found
500 - Internal Error


POST /api/message

Sends a new message. The message data should be provided in the request body.

Request Body

{
    "name": "Test name",
    "email": "name@email.com",
    "message": "This is a message"
}

Response

{
    "message": "Message delivered and saved to database."
}

Response codes

200 - OK
404 - Product not found
500 - Internal Error


Orders

POST /api/orders

Creates a new order. The order data should be provided in the request body. Requires a Bearer token for authentication.

GET /api/orders

Retrieves all orders. Requires a Bearer token for authentication.

User Registration and Login

POST /api/register

Registers a new user. The user data should be provided in the request body.

POST /api/login

Logs in a user. The user credentials should be provided in the request body.

Questions? Contact Jesper.