This is a fully asynchronous API server, that implements headless (no UI) CMS for managing articles (CRUD).
Technologies: Python 3.9, FastAPI, MySQL Percona Server 8, SQLAlchemy
Made for fun :-)
make run_docker
or
docker compose up --abort-on-container-exit
DATABASE_URL=mysql://root:@127.0.0.1:3306/articles make run
The server responds on port 8000.
For methods to create, delete, update requires authorization by HTTP field with a constant token.
Authorization: some_hardcoded_token
curl -X POST http://localhost:8000/api/v1/create \
-H 'Authorization: some_hardcoded_token' \
-H 'Content-Type: application/json' \
-d '{"topic":"Marge Simpson story", "text": "text text text"}'
curl -X PATCH http://localhost:8000/api/v1/article/1 \
-H 'Authorization: some_hardcoded_token' \
-H 'Content-Type: application/json' \
-d '{"topic":"Other topic", "text": "some text"}'
curl -X DELETE http://localhost:8000/api/v1/article/1
-H 'Authorization: some_hardcoded_token'
curl -X GET http://localhost:8000/api/v1/article/1
curl -X GET http://localhost:8000/api/v1/list?from_date=2022-06-02T15:40:00\&sort_order=desc\&sort_by=updated\&page_size=30\&page=1
All query options are optional
It's pretty simple. In general terms, you need to change MyResponse
object in the articles/api/response.py
file.
Something like this:
class MyResponse(Response):
media_type = "text/xml"
def render(self, content) -> bytes:
return dumps({'response': content}).encode("utf-8")
make test_docker
or
docker compose -f docker-compose.testing.yml up --abort-on-container-exit --force-recreate
TEST_DATABASE_URL=mysql://root:@127.0.0.1:3306/__articles_test make test
Be careful! the test database will be deleted after passing the tests!