Library site
Library website API documentation
Starting own API from scratch
Make sure pip is installed before continuing.
Install dependencies
Install the dependencies by executing the following line of code in the terminal:
Windows:
Linux(at your own risk):
Create databases
Now you can migrate to create databases
Windows:
Linux:
Create super user
Now you can create a super user via:
Windows:
Linux:
Set up email
Enter your email and application password in user/views.py from which emails will be sent.
Enter your secret key
Enter the new secret key in librarysite/settings.py
The secret key must be secure and cannot be disclosed to anyone.
How to fill JSON
Variable | Value |
---|---|
title | Book title |
img | link or path to the image |
reviews | Book rating from 1 to 5 |
content | Book description |
upc | UPC |
producttype | Product type |
price | Price (template XX.XX) |
pricetax | Price with tax (template XX.XX) |
tax | Tax (template XX.XX) |
availability | Number of books (zero if none) |
reviewscount | Number of reviews |
ganres | Genres |
date | Date the book was written (Use YYYY-MM-DD format) |
username | Username (Max 20 symbols) |
Email (Must hava domain) | |
password | Current password or new password if you want to change it (UserPasswordChangeView only) (Max 128 symbols) |
You also need to specify an access token if you want to perform certain actions (Authorization -> Bearer Token)
User rights
Site visitors can have 3 types:
- Not logged in
- Logged in
- Admin
What rights users should have for which actions you can read below.
Books
Here are the queries for working with the books database.
Get all books from database
To get information about all books you must send a GET request to the address
/api/v1/BookListView/
with the access token in JSON. (User must be logged in.)
Get all books (only brief information)
To get brief information about all books you must send a GET request to the address
/api/v1/BookPreviewView/
with the access token in JSON. (User must be logged in.)
Get all books where genre is "..." (only brief information)
To get all books where the genre is "..." you need to make a GET request to the address
/api/v1/BookGengesFilterView/
with the access token and genre in json. (User must be logged in.)
Get book where title is "..."
To get book where the title is "..." you need to make a GET request to the address
/api/v1/BookShowByTitle/
with the access token and title in json. (User must be logged in.)
Delete book from databese
To delete a book from the database you must send a DELETE request to the address
/api/v1/BookDelete/
with the access token and UPS in JSON. (User must have administrator rights.)
Add a book to the database
To add a book you must send a POST request to the address
/api/v1/BookCreate/
with the following information in JSON:
- title
- img
- reviews
- content
- upc
- producttype
- price
- pricetax
- tax
- availability
- reviewscount
- ganres
- data
(User must have administrator rights.)
Change book information
To change information about a book, send a PUT request to the address
/api/v1/BookRedact/
with the access token, UPC, and the information you want to change. (User must have administrator rights.)
Import data from books.toscrape.com
To import all books to the data base, send a POST request to the address
/api/v1/BooksImportView/
with the access token. (User must have administrator rights.)
Export all books to excel
To export all books from the data base, send a GET request to the address
/api/v1/ExportBooksExcelView/
with the access token, optional: get a specific genre / get a specific title. (User must be logged in.)
User
Here are the queries for working with the user database.
Create new user
To create a new user you must send a POST request to the address
/api/v1/UserCreate/
with the access token, username, email and password in JSON
Get information about a user
To get information about a user you must make a GET request to the address
/api/v1/UserCheck/
with the access token and username in JSON. (User must be logged in.)
Reset user password via email
Make sure you have set up your email and app password.
To reset user password you must make a POST request to the address
/api/v1/UserEmailSendView/
with the username and email in JSON.
Change user password
To change user password you must make a PUT request to address
/api/v1/UserPasswordChangeView/
with the access token, username and new password in JSON. (User must be logged in.)
SimpleJWT
Here are the queries for working with the SimpleJWT.
Create tokens
To create a tokens you must send a POST request to the address
/api/v1/token/
with the access username and password in JSON
Refresh token
To refresh a token you must send a POST request to the address
/api/v1/token/refresh/
with the access token in JSON