This is a medieval store API where you can create and read unique items for sale, create and read orders, register and login users.
Built with:
- Create and read unique items
- Create and read orders
- Register and login users
- Authentication with JWT
Installation with Docker 🐳
- Clone the repository
git clone [email protected]:lucasdximenes/medieval-store-api.git
- Enter the project folder
cd medieval-store-api
-
You need to have Docker and Docker Compose installed on your machine. If you don't have it, you can download it here and here.
-
Run the following command to start the containers
docker-compose up -d
- Connect to container
docker exec -it trybesmith
- Install dependencies and initialize API
In terminal of container
npm install && npm start
- The API will be running on port 3000. You can access it by going to http://localhost:3000
Installation without Docker 🌊
- Clone the repository
git clone [email protected]:lucasdximenes/medieval-store-api.git
- Enter the project folder
cd medieval-store-api
- Install the dependencies
npm install
-
You need to have MySQL installed on your machine. If you don't have it, you can download it here.
-
Create an
.env
file in the root of the project and add the following environment variables
MYSQL_USER=YOUR_MYSQL_USER
MYSQL_PASSWORD=YOUR_MYSQL_PASSWORD
MYSQL_HOST=YOUR_MYSQL_HOST
JWT_SECRET=YOUR_JWT_SECRET
- Run the migration script in a database manager like DBeaver
- Initialize the API
npm start
- The API will be running on port 3000. You can access it by going to http://localhost:3000
-
/login: - Login user
-
Request:
-
{ "username": "username", "password": "password" }
-
-
Response:
-
{ "token": "token" }
-
-
- /orders - Get all orders
- Response:
-
[ { "id": 1, "userId": 1, "productsIds": [1] } ]
-
- Response:
-
/orders - Create an order
-
Request:
- Headers:
Authorization: Token
- Body:
-
{ "userId": 1, "productsIds": [1] }
-
- Headers:
-
Response:
- Body:
-
{ "userId": 1, "productsIds": [1] }
-
- Body:
-
- /products - get all products
- Response:
-
[ { "id": 1, "name": "Espada curta", "amount": "10 peças de ouro", "orderId": 4 } ]
-
- Response:
-
/products - Create an product
-
Request:
- Body:
-
{ "name": "product name", "amount": "product value" }
-
- Body:
-
Response:
-
Body:
-
{ "id": 10, "name": "product name", "amount": "product value" }
-
-
-
-
/users - Register an user
-
Request:
- Body:
-
{ "username": "username", "vocation": "vocation", "level": 999, "password": "password" }
-
- Body:
-
Response:
- Body:
-
{ "token": "token" }
-
- Body:
-
credits for readme: Lucas Ximenes