This repository contains the exercises for the Skill Boost session on consuming APIs. It contains the code for running and deploying a simple FastAPI application that exposes two endpoints:
/measurements/page: a paginated endpoint that returns a list of measurements.
/measurements/very-reliable: an endpoint that, despite its name, is not very reliable and returns sometimes a 500 error.
For a full description of the endpoints and the query parameters, there is an OpenAPI specification available at /docs. You can run the API either locally via make run-api, or deploy it in the Dataminded Playground AWS account by applying the Terraform configuration in the infra directory. This will create an ECS service that is available at skillboost.playground.dataminded.cloud.
There are two exercises you can complete:
- Make the
tests/test_very_reliable.pytest pass. It uses theingest_measurementsfunction frommain_sync.pyto fetch measurements from the/measurements/very-reliableendpoint. The test is currently failing because the endpoint is not very reliable and returns sometimes a 500 error. You can modify theingest_measurementsfunction to handle these errors. Tip: some tenacity can help! - Implement the
ingest_measurementsfunctions inmain_async_measurements.pyandmain_multithreaded_measurements.pyusing theasyncioandmultithreadinglibraries, respectively. Then run the benchmark tests withmake benchmarkto see which implementation is faster. Can you explain the results?