APITestDoc

Overview

The APITestDoc is a powerful tool designed to simplify the process of testing API endpoints and generating comprehensive API documentation. With support for various HTTP methods, custom headers, and flexible output formats, it's an essential tool for developers working with APIs.

Installation

To install the APITestDoc, run the following command:

go get github.com/Trend20/apitestdoc

Commands

1. test

The test command allows you to send requests to API endpoints and view the responses.

Usage:

apitestdoc test --url <URL> --method <METHOD> [--body <BODY>] [--headers <HEADER>]

Options:

  • --url: The URL of the API endpoint (required)
  • --method: HTTP method (GET, POST, PUT, DELETE, etc.) (default: GET)
  • --body: Request body in JSON format (optional)
  • --headers: Custom headers in key:value format, separated by commas (optional)

2. generate-doc

The generate-doc command creates API documentation based on your test results.

Usage:

apitestdoc generate-doc --output <OUTPUT_FILE>

Options:

  • --output: Path to the output file (default: ./apidoc.json)
  • --format: Output format (json, markdown, openapi, or postman) (default: json)

Examples

Testing an API Endpoint

apitestdoc test --url "https://api.example.com/users" --method "GET" --headers "Authorization:Bearer token123"

Generating Documentation

apitestdoc generate-doc --output "api_documentation.json" --format openapi

Configuration

You can create a configuration file named apitestdoc.config.yml in your project root to store default settings:

default_url: "https://api.example.com"
default_headers:
  - "Content-Type: application/json"
  - "Authorization: Bearer YOUR_TOKEN"
output_format: openapi
output_file: "./docs/api_documentation.json"

Playground

Test the API Tester CLI right in your browser!


            
        

Tips and Best Practices

Troubleshooting

Q: Why am I getting a "Connection refused" error?

This error usually occurs when the API server is not reachable. Check your internet connection and verify that the API server is running and accessible.

Q: How can I include authentication in my API requests?

You can include authentication headers using the --headers option. For example: --headers "Authorization:Bearer YOUR_TOKEN"

Getting Help

For a complete list of commands and options, run:

apitestdoc --help

If you encounter any issues or have questions, please visit our GitHub repository or contact our support team.