Coman
Coman is a simple API manager designed to streamline API management and request sending. It can be used as a CLI tool or as a Rust library in your own projects.
Key Features
- Collections Management: Store APIs grouped in collections where each collection can have a base URL.
- Endpoint Management: Each endpoint is relative to its parent collection's URL. Endpoints can have multiple headers and a body.
- Header Merging: Collections can have default headers used by their endpoints. If an endpoint defines the same header as its parent collection, the endpoint header will override the collection header.
- Command Memory: Coman has a few subcommands and options that are easy to remember.
- Persist Collections: Coman saves a JSON file in the home directory.
- Pretty JSON output: By default, API results are treated as JSON unless the streaming option is defined.
- Streaming and Files: Send streams data and files.
- Prompting for Missing Data: nteractive prompts for missing data using the
:?. - Library Support: Use coman as a library in your Rust projects for programmatic API management.
Table of Contents
- Installation
- Usage as CLI
- Usage as Library
- Main Commands
- Global Options
- Command Details
- Examples
- Additional Resources
Installation
Prerequisites
- Rust (latest stable version recommended)
Installing as CLI
Install from crates.io:
Building from Source
-
Clone the repository:
-
Build the project:
-
The binary will be available at
target/release/coman.
Alternatively, you can run it directly with:
Using as a Library
See the Wiki for examples. https://github.com/bugyboo/coman
Usage as CLI
Library API Overview
Core Types:
CollectionManager- Manage collections and endpointsHttpClient- Make HTTP requestsHttpRequest- Build custom requestsHttpResponse- Response with status, headers, bodyCollection,Request,Method- Data models
CollectionManager Methods:
new(file_path)- Create manager with optional custom fileadd_collection(name, url, headers)- Add/update collectionadd_endpoint(collection, name, path, method, headers, body)- Add/update endpointdelete_collection(name)- Delete a collectiondelete_endpoint(collection, endpoint)- Delete an endpointget_collection(name)- Get collection detailsget_endpoint(collection, endpoint)- Get endpoint detailslist_collections()- List all collections
HttpClient Methods:
get(url),post(url),put(url),delete(url),patch(url)- Create requestsexecute_endpoint(manager, collection, endpoint)- Execute saved endpoint
Main Commands
- list: List APIs Collections
- man: Managing APIs
- req: Sending requests
- run: Running collections endpoints
- url: Print request URL with headers and body
- test: Run tests on collections
- help: Print this message or the help of the given subcommand(s)
Global Options
-h, --help: Print help-V, --version: Print version
Command Details
List APIs Collections (list)
List all collections and endpoints.
Usage:
Options:
-c, --col <COL>: Specify a collection (default: all)-e, --endpoint <ENDPOINT>: Specify an endpoint (default: all)-q, --quiet: Quiet mode-v, --verbose: Verbose output-h, --help: Print help
Managing APIs (man)
Manage API collections and endpoints.
Usage:
Commands:
- list: List collections and endpoints
- update: Update a collection or endpoint headers and body
- delete: Delete a collection or endpoint
- copy: Copy a collection or endpoint
- col: Add a new collection
- endpoint: Add a new endpoint to a collection
- help: Print this message or the help of the given subcommand(s)
Options:
-h, --help: Print help
Sending Requests (req)
Send HTTP requests.
Usage:
Commands:
- get
- post
- put
- delete
- patch
- help: Print this message or the help of the given subcommand(s)
Options:
-v, --verbose: Verbose output-s, --stream: Stream the request/response (read bytes from stdin and send as the request body or multipart data to the endpoint)-h, --help: Print help
Running Collections Endpoints (run)
Run endpoints from collections.
Usage:
Options:
-v, --verbose: Verbose output-s, --stream: Stream the request/response (output response as bytes)-h, --help: Print help
Print Request URL (url)
Print the request URL with headers and body.
Usage:
Options:
-h, --help: Print help
Examples
Managing Collections
-
Add a new collection:
-
Add an endpoint to a collection:
-
List all collections:
-
List endpoints in a specific collection:
Sending Requests
-
Send a GET request:
-
Send a POST request with a body:
-
Send a request with headers:
Running Endpoints
- Run an endpoint from a collection:
Prompting for Missing Data
Coman supports interactive prompts for missing data using the :? placeholder. When a header value or request body contains :?, Coman will prompt you to enter the value at runtime. This is useful for sensitive data like tokens or dynamic values that change between requests.
Missing Header Data
If a header value contains :?, Coman will prompt for the correct value:
-
Create an endpoint with a placeholder in the header:
-
When you run the endpoint, Coman will prompt:
# Output: Header value for key 'Authorization' is missing data. Please provide the correct value: # Enter your token and press Enter
Missing Body Data
If the request body contains :?, Coman will prompt for each placeholder:
-
Create an endpoint with placeholders in the body:
-
When you run the endpoint, Coman will prompt for each
:?:# Output: Missing data at position 14 - {"username": ":?", "email": ":?"}. Please provide the correct value: # Enter "john_doe" and press Enter # Output: Missing data at position 31 - {"username": "john_doe", "email": ":?"}. Please provide the correct value: # Enter "john@example.com" and press Enter
Direct Requests with Placeholders
You can also use placeholders in direct requests:
-
URL with placeholder:
# Prompts for the user ID -
Headers and body with placeholders:
# Prompts for API key, then password
Note: Prompting is disabled when using the
-s(stream) option to allow for non-interactive piped operations.
Pipe operation
Coman supports reading request body from standard input when piping data. This is useful for sending JSON payloads or other data directly from files or other commands.
-
Send JSON data from a file as the request body:
| -
Pipe output from another command as the request body:
|
When data is piped to coman, it will override any body defined in the endpoint configuration.
Updating and Deleting Headers/Body
To remove a header or clear the body from a collection or endpoint, use the update command with an empty value:
-
Remove a header from an endpoint:
-
Clear the body from an endpoint:
For more help, use the help command with any of the subcommands: