Welcome to the MedievalCraft API, an API for managing a store of medieval items, including custom-made swords. This API was developed using Typescript and Sequelize and includes JWT authentication as well as tests to ensure the correct functioning of the features.
-
Typescript: The API is developed using Typescript, which provides static typing and improved developer tooling for JavaScript.
-
Sequelize: Sequelize is used as the Object-Relational Mapping (ORM) tool for interacting with the database. It simplifies database operations and allows you to work with a variety of database systems.
-
JWT Authentication: JSON Web Tokens (JWT) are used for user authentication. This secure method of authentication is widely adopted for securing APIs.
-
Testing Framework: The API includes a testing framework for ensuring the reliability of the Service and Controller layers.
Follow these steps to set up and run the API on your machine:
- Clone the repository:
git clone https://github.com/thiesac/medievalcraft-api.git
- Navigate to the project directory:
cd medievalcraft-api
- Install dependencies:
npm install
-
Configure the database. Make sure to set up the database credentials in the
.env
file. -
Run database migrations:
npm run sequelize db:migrate
- Start the server:
npm start
The API will be available at http://localhost:3000
.
Here are the main functionalities of the API:
To register a new product, make a POST request to /products
. The request body should follow the structure below:
{
"name": "Thor's Hammer",
"price": "30 pieces of gold",
"orderId": 4
}
Please note that the orderId
field should be unique for each product since the products are unique. The registered products will be saved in the products table of the database.
To list all available products, make a GET request to /products
. This will return a list of registered products.
To list all orders and the associated products, make a GET request to /orders
.
To log in as a user, make a POST request to /login
. The request body should follow the structure below:
{
"username": "your-username",
"password": "your-password"
}
If the credentials are valid, a JWT token will be generated and returned in the response. You can use this token to authenticate other requests.
Be sure to test the API's functionalities and explore more details in the endpoint documentation.
The API includes tests to ensure the correct functioning of the Service and Controller layers. You can run the tests using the following command:
npm test
This will ensure that the API is working as expected.
Enjoy using the MedievalCraft API to manage your medieval items store!
Contributions to this project are welcome! If you have bug fixes, feature additions, or improvements, please feel free to open an issue or submit a pull request.
I would like to acknowledge and express my gratitude to Trybe for their support and guidance throughout the development of this educational resource.