This is the technical test project for API oriented backends.
To use the application you'll need:
- The webserver container
- The database container
- An authorized user
Run the following commands to get everything in place:
make build
make add-user
- Take a note of the token returned by the last command, you'll need it to issue requests.
make test
This command executes the test suite inside a docker container.
Use the command:
make start
To get the containers up and running.
Use the command:
make open
To open a browser at the root URL.
At http://localhost:8080/docs
you'll see the Open API specification.
To alter data issue non-GET requests to the desired endpoint.
Keep in mind that this will only work if you use a valid token, like the one you got from make add-user
.
For instance, to add a character you can use a command such as:
curl -X POST -H 'X-AUTH-TOKEN: 1ee143556a6f260858b3b90f8cc51f01a45e' -H "Content-Type: application/json" -d '{"name":"Mauro", "faction_id": "2", "equipment_id": "2", "kingdom": "My kingdom", "birth_date": "1977-12-22"}' http://localhost:8080/characters/
Replace 1ee143556a6f260858b3b90f8cc51f01a45e
with your token.
To delete a faction you can use a command such as:
curl -X DELETE -H 'X-AUTH-TOKEN: 1ee143556a6f260858b3b90f8cc51f01a45e' -H "Content-Type: application/json" http://localhost:8080/factions/
To update an equipment you can use a command such as:
curl -X PATCH -H 'X-AUTH-TOKEN: 1ee143556a6f260858b3b90f8cc51f01a45e' -H "Content-Type: application/json" -d '{"type":"weapons"}' http://localhost:8080/equipments/3
make stop
This commands stops the docker containers necessary to run the application
make build-docs
This command generates the OpenAPI specification file (var/openapi.yaml
).
Run this command to update the documentation available for clients.
To deploy the application in a production environment, follow the same initial steps and then alter the contents of the file app/.env
from
APP_ENV=dev
To
APP_ENV=prod
After this change, in case of failure, the user will receive a generic error instead of details that might jeopardize the availability of the service.
Use the command
make help
To get a full list of available commands
- Add logging
- Improve error handling
- Use finer-grained authorization
- Implement authentication via JWT
- Prepare a specific docker image for production based on https-portal