Python RestAPI using Quart ASGI framework. It runs on HTTP/2 and will be HTTP/3 when mainstream browsers support it in the near future.
- This project uses PostgreSQL database with SQLAlchemy ORM with marshmallow for object SerDes.
$ pipenv install --python=/path/to/python
$ cd src
$ pipenv install --python=/path/to/python
$ cd test
$ pipenv install --python=/path/to/python
- Firstly, create an empty database "library" in PostgreSQL
- run migrations initialization with db init command:
$ pipenv run alembic init migrations
$ pipenv run alembic revision --autogenerate -m "Initial migration"
$ pipenv run alembic upgrade head
- There will be 3 tables, "users", "books", and "authors" created in the PostgreSQL database "library" after the
upgrade
.
- There are 7 test cases
- JWT token generation and decoding
- HomeController
- FibonacciController
$ pytest -v
$ python -m pytest
- Integrated with CircleCI
./quart.sh
{
"firstname": "First Name",
"lastname": "LastName",
"email": "firstname.lastname@email.com",
"password": "P@$$w0rd"
}
{
"email": "firstname.lastname@email.com",
"password": "P@$$w0rd"
}
- Response:
{
"jwt_token": "token string"
}
Key: api-key
Vaue: jwt_token from the login response
{
"email": "jk@email.com",
"firstname": "JK",
"lastname": "Rowing"
}
{
"author_id": 1,
"isbn": "123456",
"page_count": "123",
"title": "My First Book"
}
- Books table has a foreign key id to Authors.id and this is defined as required in BookSchema.
- Therefore, when a DELETE RESTful operation is sent to the application to delete an author which has associated book:
mysql.connector.errors.IntegrityError: 1048 (23000): Column 'author_id' cannot be null
- Headers:
Key: api-key
Vaue: jwt_token from the login response