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 Flask 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 fixed number of tests from the database and stores them in the cache. Users receive one test from the cache per call, which helps reduce database requests for every endpoint call. The tests are sorted by the datetime_shown field, so the test that was shown the longest time ago is displayed first. The updatestatus endpoint simply records the datetime when a test is shown, keeping the database up to date.
- Flask: For building the web API.
- SQLAlchemy: For ORM functionality with MySQL.
- Flask-Migrate: To handle database migrations.
- PyMySQL: MySQL client for Python.
- Redis: Used for managing the cache layer.
- Pydantic: For data validation.
- Flask-RESTX: For creating RESTful services and documenting them.
- Pytest: For writing and running unit tests.
git clone https://github.com/yourusername/EnGram_sync.gitcd EnGram_syncpip install -r requirements.txtCreate .env and .test.env files based on the provided examples.
Create the database in MySQL and initialize and apply migrations:
flask db init
flask db migrate -m "Initial migration"
flask db upgradeYou 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:\RedisSet 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.confredis-server.exe redis-prod.confpython api/app.pypytest -v tests/test_api.py And check Swagger: http://127.0.0.1:8000/docs