The API generates tests for English grammar learning and can be used as a backend for English learning-related projects.
The app was built using Quart with asynchronous programming and has two endpoints: gettests
and updatestatus
.
- The first endpoint generates one test each time it's called.
- The second endpoint updates the date and time when the test was displayed on the frontend.
When the gettests
endpoint is called, the app retrieves a set number of tests from the database and stores them in the cache. Users receive one test from the cache per call, reducing the need for frequent database queries. The updatestatus
endpoint ensures test variation by sorting the tests by the datetime_shown field, so users always receive the oldest available test.
- Quart: For building the web API with asynchronous capabilities.
- SQLAlchemy: For ORM functionality with MySQL.
- Alembic: To handle database migrations.
- aiomysql: MySQL client for asynchronous programming.
- Aioredis: Used for managing the cache layer asynchronously.
- Pydantic: For data validation.
- quart_schema: For request and response validation.
- pytest-asyncio: For writing and running asynchronous unit tests.
git clone https://github.com/yourusername/EnGram_async.git
cd EnGram_async
pip install -r requirements.txt
Create .env and .test.env files based on the provided examples.
Create the database in MySQL and initialize and apply migrations:
alembic init migrations
alembic revision --autogenerate -m "Database creation"
alembic upgrade c14ac4dc5999 # Use your own revision ID from the generated migration file
You can use that Initial Migration Script which is provided in this repository. Also populate the database with data.
Download Redis and place the folder on disk C (for example). Open a command prompt and navigate to the Redis folder:
cd C:\Redis
Set up configuration files. You can either modify the redis.windows.conf or create two copies: redis-prod.conf and redis-test.conf, and specify different ports in each file. Start Redis servers:
redis-server.exe redis-test.conf
redis-server.exe redis-prod.conf
python api/app.py
pytest -v tests/test_api.py
And check Swagger: http://127.0.0.1:8000/docs