An API for a bookstore using Express and MongoDB with Mongoose. This project is used to test the compatibility of express with Bun. You will find the Node.js version in the main branch and the version for Bun in the branch feature-migrate-to-bun.
This API includes the following features:
Feature | Info |
---|---|
ORM Integration | Mongoose |
Logging | Winston |
Logging of the HTTP-Requests | Morgan |
Validations | Joi |
Secure application by setting HTTP-Headers | Helmet |
Response Compression | Compression |
Error Handling | Own Error Handler |
Install the dependencies
npm install
Create a .env file with the following properties:
- URL to a running MongoDB.
database_url="<url>"
To run the app locally:
npm run dev
To run the minified version of the app:
npm run build
npm run prod
Property | Value |
---|---|
Endpoint | /api/v1/books |
Method | POST |
Body | Book & Author |
Response | Created Book |
{
"title": "<title",
"isbn": "<isbn></isbn>",
"author": {
"name": "<full name>"
}
}
Property | Value |
---|---|
Endpoint | /api/v1/books |
Method | GET |
Body | - |
Response | All books |
Property | Value |
---|---|
Endpoint | /api/v1/books/{id} |
Method | GET |
Body | - |
Response | Book |
Property | Value |
---|---|
Endpoint | /api/v1/books?author= |
Method | GET |
Body | - |
Response | Books by Author |
Property | Value |
---|---|
Endpoint | /api/v1/books/{id}/author |
Method | GET |
Body | - |
Response | Author |
Property | Value |
---|---|
Endpoint | /api/v1/books/{id} |
Method | PUT |
Body | Book & Author |
Response | Updated Book |
{
{
"title": "<Updated Title>",
"author": {
"name": "<Updated Author>"
}
}
}
Property | Value |
---|---|
Endpoint | /api/v1/books/{id} |
Method | DELETE |
Body | - |
Response | - |
Property | Value |
---|---|
Endpoint | /api/v1/authors |
Method | POST |
Body | Author |
Response | Created Author |
{
"name": "<full name>"
}
Property | Value |
---|---|
Endpoint | /api/v1/authors |
Method | GET |
Body | - |
Response | All authors |
Property | Value |
---|---|
Endpoint | /api/v1/authors/{id} |
Method | GET |
Body | - |
Response | Authors |
Property | Value |
---|---|
Endpoint | /api/v1/authors/{id} |
Method | PUT |
Body | Author |
Response | Updated Author |
{
"name": "<updated name>"
}
Property | Value |
---|---|
Endpoint | /api/v1/authors/{id} |
Method | DELETE |
Body | Author |
Response | - |