Hi! I'm Andrew, and this is hypermodern-fastapi. This repo implements a single REST endpoint, per the animated SVG below:
First install Poetry however you wish. Then run
poetry install
poetry run wolt-summer-eng-assignment --helpThen go ahead and send your payloads to whatever port it assigns you, most likely localhost:8000. Among other things Poetry also makes it easy to run the code tests for yourself by using poetry run pytest or nox.
Tested on a fresh Docker pull of Ubuntu, but I can make no guarantees it is seamless.
First ensure your system has the required dependencies, by running
pip install -r requirements.txtin the root directory. Then simply enter the src folder and run as a module:
cd src/
python -m wolt_summer_eng_assignmentYou should now be able to send your request payloads however you wish to localhost.
I have included a copy of the example.sh script from
the animated SVG above in the
root directory of this project as payload-example.sh to
make things as easy as possible to debug.
With the server running in one terminal, and assuming
it has mapped to localhost:8000, simply run
bash payload-example.shto send a payload JSON to the server. It will print the response payload JSON in turn. You can run this every 2 seconds as you dynamically play around with the variables by running
watch 'bash payload-example.sh'in a separate terminal as well.
There are a lot of files in here, I know. I'm a maximalist when it comes to setting up new projects, but I'm not dogmatic about it.
Here are the important files to look at for my solution:
.
├── src
│ └── wolt_summer_eng_assignment
│ ├── logic.py
│ ├── __main__.py
└── tests
├── test_logic.py__main__.pycontains the FastAPI logic that we run in a loop to create the server.logic.pycontains the data models and business logic of the application.- These used to be in
__main__.pyas well, but I figured splitting them into their own file made it easier to keep track of everything.
- These used to be in
test_logic.pyis where I implement the unit tests forlogic.py. These were incredibly helpful to write!
This is just a preliminary assignment, but here are some directions I could go.
- Figure out a way to test the server code in
__main__.py. I factored out the business logic tologic.pyand have that tested fairly well (writing those unit tests actually showed me a lot of flaws in my original thinking), but I don't have anything in place testing the FastAPI code itself yet. I'm not doing anything fancy with it but it would be nice. - Fix everything
noxcomplains about. I dopoetry run pytestin the animated SVG but that's actually just the tip of the iceberg. You can runnoxon this repo to see a lot more places where things can be fixed, dependency patches could be applied, etc. - Use types!
mypyexists in here and would probably make this look much more professional if I were to use it. - Make
__main__.pysmaller. There are bits of__main__.pyI don't think have to be there, and improving the CLI-based help would be practically mandatory for me if I were to ship this for the general public.
All documented in Wolt's "Specifications" section.
This project was generated from @cjolowicz's Hypermodern Python Cookiecutter template.