Superheroes and Supervillains are always battling it out, but how do we know who wins? This repo exposes a FastAPI HTTP service that answers that question.
The GET /battle endpoint in superheroes_python/main.py accepts a hero and villain query parameter and returns the character that would win in a battle.
The characters and their stats are stored in a JSON file in AWS S3 - https://s3.eu-west-2.amazonaws.com/build-circle/characters.json
In order to run the project, you will need:
Once you have downloaded the repo:
- Run
pip install -r requirements.txtto install dependencies. - Run the API with
uvicorn superheroes_python.main:app --reload - The tests can be run with
pytest
Returns the winner of a battle between a hero and a villain.
Query parameters:
hero— name of the herovillain— name of the villain
Example:
GET /battle?hero=Superman&villain=Joker
Note: This tech test is deliberately loose. We're looking for your opinions and coding style.
Above all, Build Circle value clear, well tested code.
-
Familiarise yourself with the code. Feel free to point out any issues or opinions you have about it. No right answers here but hopefully will drive good discussion.
-
Currently the
superheroes_python/get_characters.pyfunction is mocked in our tests. The real implementation throws an error. Make this function work by loading and parsing the characters from a JSON document in S3 here https://s3.eu-west-2.amazonaws.com/build-circle/characters.json (bonus points for a decent test for this). -
Edge cases. Only the happy path is covered. Let's think about what could go wrong and write some code to handle it.
-
Each hero usually has a nemesis. This is captured in the
weaknessfield in the JSON. If a hero is fighting a villain that matches the villain in theirweaknessfield their score is weakened by 1 point. Let's write some code to handle this.