Skip to content

feat: Add test API request tool with code generation#77

Open
mattpodwysocki wants to merge 1 commit intofeature/api-endpoint-explorerfrom
feature/test-api-request-tool
Open

feat: Add test API request tool with code generation#77
mattpodwysocki wants to merge 1 commit intofeature/api-endpoint-explorerfrom
feature/test-api-request-tool

Conversation

@mattpodwysocki
Copy link
Contributor

Summary

Implements test_api_request_tool to execute actual Mapbox API requests and generate copy-paste ready code examples.

This PR targets feature/api-endpoint-explorer (PR #75) and depends on the endpoint definitions from that branch.

Features

  • Real HTTP requests: Makes actual API calls to Mapbox endpoints
  • Code generation: Generates snippets in curl, JavaScript, and Python
  • Response inspection: Returns actual responses with status codes and headers
  • Execution metrics: Shows timing and rate limit information
  • Token security: Masks access tokens in generated code
  • Full HTTP support: Handles GET, POST, PUT, PATCH, DELETE methods
  • Parameter handling: Supports path, query, and body parameters

Use Cases

  1. Test API calls: Verify requests work before integrating into your app
  2. Learn by example: Get working code snippets you can copy-paste
  3. Debug issues: See actual responses and timing information
  4. Generate boilerplate: Get starter code in your preferred language

Complete API Workflow

This tool completes the API development trio:

  1. explore_mapbox_api_tool → Discover APIs and operations
  2. validate_api_request_tool → Validate request structure (PR feat: Add API request validator tool #76)
  3. test_api_request_tool → Execute and generate code ✨ (this PR)

Implementation

  • Extends MapboxApiBasedTool with proper lifecycle
  • Uses endpoint definitions from MAPBOX_API_ENDPOINTS (PR feat: Add API endpoint explorer tool #75)
  • Generates idiomatic code for each language
  • Masks tokens in all generated code
  • Comprehensive error handling
  • Returns both markdown and structured output

Testing

  • ✅ Comprehensive test coverage
  • ✅ All 568 tests pass
  • ✅ Tool snapshot updated
  • ✅ ESLint clean
  • ✅ Build successful

Example Usage

Input:

{
  "api": "geocoding",
  "operation": "forward-geocode",
  "parameters": {
    "path": {
      "mode": "mapbox.places",
      "query": "San Francisco"
    }
  },
  "generateCode": true,
  "codeLanguages": ["curl", "javascript", "python"]
}

Output:

  • ✅ Actual API response
  • 🔢 Status code and headers
  • ⏱️ Execution time
  • 💻 Code snippets in all requested languages

Example Prompts

  • "Test the geocoding API with query 'San Francisco'"
  • "Make a request to list my styles and show me the curl command"
  • "Call the directions API from Paris to Lyon and generate code examples"
  • "Test creating a token and show me how to do it in JavaScript"
  • "Execute a tilequery request and generate Python code"

Documentation

  • Updated CHANGELOG.md with feature details
  • Updated README.md with tool documentation and examples
  • Clear error messages for invalid APIs/operations

Dependencies

Addresses

Closes #72

🤖 Generated with Claude Code

Implements test_api_request_tool to execute actual Mapbox API requests
and generate copy-paste ready code examples.

Features:
- Makes real HTTP calls to Mapbox APIs
- Returns actual responses with status codes and headers
- Generates code snippets in curl, JavaScript, and Python
- Shows execution timing and rate limit information
- Masks access tokens in generated code for security
- Supports all HTTP methods (GET, POST, PUT, PATCH, DELETE)
- Handles path, query, and body parameters

Complements explore_mapbox_api_tool (discover APIs) and
validate_api_request_tool (validate requests) for a complete
API development workflow: explore → validate → test.

Addresses: #72

Changes:
- Add TestApiRequestTool implementation
- Register in toolRegistry.ts
- Add comprehensive test coverage
- Update CHANGELOG.md with feature details
- Update README.md with tool documentation and examples

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@mattpodwysocki mattpodwysocki requested a review from a team as a code owner February 12, 2026 22:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant