This API allows you to manage a collection of books. You can perform CRUD operations including creating, retrieving, updating, and deleting book records.
Endpoint: POST /api/v1/token/register
Description: Create new account.
Endpoint: POST /api/v1/token/login
Description: Login account to get an access token.
Endpoint: POST /api/v1/token/logout
Description: Log-out account by revoking the token.
Endpoint: GET /api/v1/books
Description: Retrieve a list of all books.
Endpoint: POST /api/v1/books
Description: Add a new book to the collection.
Endpoint: GET /api/v1/books/{isbn}
Description: Retrieve a specific book by its ISBN.
Endpoint: PUT /api/v1/books/{isbn}
Description: Update the details of a specific book by its ISBN.
Endpoint: DELETE /api/v1/books/{isbn}
Description: Delete a specific book by its ISBN.
- username: The account user
- password: The account password
- isbn: The International Standard Book Number (ISBN) of the book.
- title: The title of the book.
- author: The author of the book.
- genre: The genre of the book.
- year: The year the book was published.
- publisher: The publisher of the book.
- quantity: The quantity of the book in stock.
- price: The price of the book.
To run this API locally, follow these steps:
-
Clone the repository:
$ git clone https://github.com/nordszamora/Book-Management-API.git
-
Navigate to the project directory:
$ cd Book-Management-API
-
Install the required packages:
$ pip install -r requirements.txt
-
Initialize the database:
$ flask db init
-
Apply the database migrations:
$ flask db migrate -m 'books'
-
Upgrade the database:
$ flask db upgrade
-
Run the application:
$ python app.py
-
Navigate into localhost:
http://127.0.0.1:5000/api/v1/<route>
-
Auth:
$ curl -X POST http://127.0.0.1:5000/api/v1/token/register -H "Content-Type: application/json" -d '{"username": "<user>", "password": "<pass>"}' $ curl -X POST http://127.0.0.1:5000/api/v1/token/login -H "Content-Type: application/json" -d '{"username": "<user>", "password": "<pass>"}' $ curl -X POST http://127.0.0.1:5000/api/v1/token/logout -H "Content-Type: application/json" -H "Authorization: Bearer <token>"
-
Read, Add, Edit & Delete Book:
$ curl http://127.0.0.1:5000/api/v1/books $ curl http://127.0.0.1:5000/api/v1/books/<ISBN> $ curl -X POST http://127.0.0.1:5000/api/v1/books -H "Content-Type: application/json" -H "Authorization: Bearer <token>" -d '{"isbn": <isbn>, "title": "<title>", "author": <author>", "genre": "<genre>", "year": <year>, "publisher": "<publisher>", "quantity": <quantity>, "price": <price>}' $ curl -X PUT http://127.0.0.1:5000/api/v1/books/<ISBN> -H "Content-Type: application/json" -H "Authorization: Bearer <token>" -d '{"isbn": <isbn>, "title": "<title>", "author": "<author>", "genre": "<genre>", "year": <year>, "publisher": "<publisher>", "quantity": <quantity>, "price": <price>}' $ curl -X DELETE http://127.0.0.1:5000/api/v1/books/<ISBN> -H "Content-Type: application/json" -H "Authorization: Bearer <token>"
This project is licensed under the MIT License. See the LICENSE file for details.