Build a simple Python API that:
- Loads data from two JSON files:
order_lines.jsonandproducts.json. - Joins them to enrich each order line with product details.
- Returns filtered order lines via an API endpoint based on a
product_idquery parameter. - Secures the endpoint with a basic API key check.
- Use Flask or FastAPI.
- Store JSON files in the
data/directory. - Secure the API using a static API key:
test123 - Run locally with
python main.pyor equivalent. - Handle edge cases appropriately (missing product_id, invalid API key, etc.).
python-coding-test/
├── data/
│ ├── order_lines.json
│ └── products.json
├── README.md
└── main.py (you will implement this)
curl "http://localhost:8000/orders?product_id=555"Note: The API requires authentication with API key test123. You'll need to determine how to implement the API key validation.
[
{
"order_id": 101,
"product_id": 555,
"quantity": 2,
"product_name": "Blue T-Shirt",
"price": 25.00
},
{
"order_id": 103,
"product_id": 555,
"quantity": 3,
"product_name": "Blue T-Shirt",
"price": 25.00
},
{
"order_id": 106,
"product_id": 555,
"quantity": 1,
"product_name": "Blue T-Shirt",
"price": 25.00
}
]- Review the data files in the
data/directory to understand the structure. - Implement
main.pyaccording to the requirements above. - Test your implementation using the example request.
- Ensure your code handles edge cases gracefully.
- What happens when
product_idis not provided? - What happens when
product_iddoesn't match any orders? - What happens when the API key is missing or incorrect?
- How will you implement API key authentication?
- Consider error handling and appropriate HTTP status codes.
- Think about code organization and readability.
You have two options for completing this test:
Work on this test without AI assistance. This allows us to evaluate your direct coding skills, problem-solving approach, and Python expertise.
You may use AI tools (ChatGPT, GitHub Copilot, Cursor, etc.) to help you complete this test. This is completely acceptable and encouraged if it reflects how you would work in a real development environment.
If you choose Option 2:
- Use AI assistance in whatever way feels natural to your workflow
- We'll discuss your process and approach during the review
- Please indicate in your submission which option you chose and, if using AI assistance, briefly describe how you used it
Once complete, please share:
- Your
main.pyfile - Any additional files you created (requirements.txt, etc.)
- A brief note on your approach and any assumptions you made
- Whether you used AI assistance and how (if applicable)
This test is designed to take approximately 1-2 hours, depending on your approach and whether you use AI assistance.
Good luck!