API Test Harness Scaffold¶
This assignment guides you through building a reusable command-line tool for testing REST APIs. The goal is to create a harness that can issue requests to any endpoint, capture responses, and save logs for later analysis. The resulting toolkit pairs with the AI Code Generation Task whenever your generated CLI needs to exercise external services.
Objectives¶
- Reusable – Accept base URLs, endpoints, and authentication details via configuration.
- Flexible – Support common HTTP methods (GET, POST, PUT, DELETE) and arbitrary headers.
- Observable – Output request/response data in both the console and log files for debugging.
- Extensible – Structure the project so additional features (e.g., concurrency, authentication plugins) can be added later.
Setup¶
- Create a new Python project using
venvorconda. - Install required packages:
pip install requests pyyaml - Scaffold the following files:
harness.py– main entry point for executing API calls.config.yaml– stores base URL, default headers, and auth tokens.README.md– usage instructions.
Basic Flow¶
flowchart TD
Start(["Run harness.py"]) --> LoadConfig{{"Read config.yaml"}}
LoadConfig --> BuildRequest{{"Construct HTTP request"}}
BuildRequest --> Send["Send request via requests library"]
Send --> Log["Log response status and body"]
Log --> End(["Save log & exit"])
Example Configuration¶
base_url: "https://api.example.com"
endpoints:
- path: "/users"
method: "GET"
- path: "/posts"
method: "POST"
body: {}
headers:
Authorization: "Bearer <token>"
Deliverables¶
- Working
harness.pycapable of readingconfig.yamland making requests. - Example log file showing successful calls to two sample endpoints.
- Updated
README.mddescribing setup, configuration options, and how to extend the tool.
Submission¶
Push your code to the provided repository and open a pull request. Include screenshots or log snippets demonstrating your harness successfully calling at least two endpoints. Mention any known limitations or future improvement ideas in the PR description.
Related assignments¶
- AI Code Generation Task – shows where this API harness accelerates validation when LLM-generated tools integrate with web services.