MyBookshelf API is a RESTful API that enables users to manage their personal book collections. This API comes with API Key-based authentication system and integration with Google Books API for book searching.
- User registration and login with unique API Key.
- CRUD (Create, Read, Update, Delete) for personal book collection.
- Book search through Google Books API.
- Endpoint protection using API Key.
- Node.js
- Express.js
- MongoDB Atlas
- Mongoose
- UUID
- Axios
- CORS
mybookshelf-api/ ├── config/ │ ├── db.js ├── controllers/ │ ├── authController.js │ └── bookController.js ├── middlewares/ │ └── apiKeyMiddleware.js ├── models/ │ ├── User.js │ └── Book.js ├── routes/ │ ├── authRoutes.js │ └── bookRoutes.js ├── utils/ │ ├── swagger-output.json │ └── swagger.js ├── .env ├── .env.example ├── .gitignore ├── LICENSE ├── package-lock.json ├── package.json └── README.md ├── server.js ├── vercel.json-
Clone this repository
git clone https://github.com/killflex/mybookshelf-api.git cd mybookshelf-api -
Install dependencies
npm install
-
Create
.envfileMONGODB_URI=your_mongodb_connection_string
-
Run the server
npm start
Server will run on
http://localhost:5000
After registration or login, users will receive an apiKey that must be included in the header for every request to protected endpoints:
x-api-key: your_api_keyAPI documentation is available through Swagger UI at:
GET /api-docs
-
POST /api/auth/register-
Body:
{ "username": "your_username", "password": "your_password" } -
Response:
{ "apiKey": "generated_api_key" }
-
-
POST /api/auth/login-
Body:
{ "username": "your_username", "password": "your_password" } -
Response:
{ "apiKey": "your_api_key" }
-
All book endpoints require x-api-key header.
-
GET /api/books- Description: Get all books belonging to the user.
-
POST /api/books-
Body:
{ "title": "Book Title", "author": "Author Name", "description": "Book Description" }
-
-
PATCH /api/books/:id-
Body:
{ "title": "Updated Title", "author": "Updated Author", "description": "Updated Description" }
-
-
DELETE /api/books/:id- Description: Delete book by ID.
-
GET /api/books/search-books?q=keyword- Description: Search books using Google Books API.
Use Postman to test the endpoints:
-
Registration/Login:
-
Send a
POSTrequest to/api/auth/registeror/api/auth/loginwith appropriate JSON body. -
Save the
apiKeyfrom the response.
-
-
Access Book Endpoints:
-
Add
x-api-keyheader with the obtainedapiKeyvalue. -
Send requests to book endpoints as needed.
-
This project can be deployed using platforms like Vercel or Heroku. Make sure environment variables ( MONGODB_URI ) are properly configured in the deployment platform.
- Make sure to keep your
apiKeysecure.
- @killflex – Original author
