From the course: Build REST APIs with FastAPI

Unlock this course with a free trial

Join today to access over 24,200 courses taught by industry experts.

Challenge: Query logs

Challenge: Query logs

In this challenge, you're going to write an HTTP server that changes the response type depending on the user request. So we are going to query the logs and you should accept either offset or count. So for example, get/logs, the offset is 10, and I want 20 logs. And there is a db.py. You choose query logs to get the logs. And you should return them as a JSON response. So count, offset, and then logs. But if the HTTP accept header in the request is text/csv, you should return a CSV format with level, time, message, and then the messages. If there are no logs that matches the query, return a 404 (NOT_FOUND) response. Don't forget to validate everything.

Contents