mc-api-cli
v1.0.4
Published
A beautiful CLI API client with Postman-like features
Maintainers
Readme
mc-api-cli: A Powerful Command-Line Tool for API Requests
mc-api-cli is a versatile command-line interface (CLI) tool designed to simplify API request building, execution, and management. With a sleek browser-based UI, it allows you to construct and send API requests, authenticate with Salesforce orgs, save requests to collections, and view responses in a polished format. Whether you're a developer, tester, or Salesforce administrator, mc-api-cli streamlines your workflow with features like JSON response visualization, cURL command generation, and support for custom ports.
Features
- Interactive Web UI: Build and send API requests through a modern browser interface
- Salesforce Authentication: Seamlessly authenticate with Salesforce orgs using the Salesforce CLI (
sf) for secure API access. - Request Collections: Save and organize API requests into reusable collections stored as JSON.
- JSON Response Viewer: View JSON responses in a Monaco Editor with syntax highlighting and an "Export JSON" feature.
- DataTables Support: Display tabular data (CSV or JSON arrays) in an interactive DataTable with export options.
- cURL Command Generation: Generate and copy cURL commands for requests
- Custom Port Configuration: Run the UI server on a custom port using the
-poption (defaults to 3000). - Cross-Platform: Works on macOS, Linux, and Windows with Node.js.
Installation
Install mc-api-cli globally via npm:
npm install -g mc-api-cliPrerequisites
- Node.js: Version 14 or higher (
node --versionto check). - Salesforce CLI: Required for Salesforce authentication. Install it from Salesforce CLI.
npm install @salesforce/cli --global
Usage
mc-api-cli provides three main commands: request, auth, and import. Run mc-api-cli --help for a full list of commands and options.
1. Authenticate with Salesforce
Authenticate with a Salesforce org to enable authenticated API requests.
mc-api-cli auth -u <username> -u, --username <username>: Salesforce username (e.g.,[email protected]or[email protected]).
Example:
mc-api-cli auth -u username Note: Ensure the org is authorized with the Salesforce CLI:
sf force auth web login -r <instanceUrl>2. Send an API Request
Open a browser-based UI to build and send API requests.
mc-api-cli request [-m <method>] [-u <url>] [-c <collection>] [--header <header...>] [--param <param...>] [-d <data>] [-u <username>] [-p <port>]-m, --method <method>: HTTP method (default:GET).-u, --url <url>: Request URL.-c, --collection <collection>: Collection name to prefill or save the request.--header <header...>: Headers inkey:valueformat (multiple allowed).--param <param...>: Query parameters inkey=valueformat (multiple allowed).-d, --data <data>: Request body as a JSON string.-u, --username <username>: Salesforce org username for authentication.-p, --port <port>: Port for the UI server (default:3000).
Example:
mc-api-cli request -u https://jsonplaceholder.typicode.com/posts/1 -m GET --header "Accept: application/json" -p 3001This opens a browser at http://localhost:3001 with a prefilled GET request. The UI allows you to:
- Modify the request (method, URL, headers, params, body).
- Select a Salesforce org for authentication.
- Save the request to a collection.
- View the response in a Monaco Editor (for JSON), DataTable (for CSV/JSON arrays), or
<pre>tag. - Copy the equivalent cURL command or export JSON responses.
3. Import a Collection
Import a collection of saved requests from a JSON file.
mc-api-cli import -f <file>-f, --file <file>: Path to the JSON file containing the collection.
Example Collection File (collection.json):
{
"TestCollection": {
"name": "TestCollection",
"requests": [
{
"method": "GET",
"url": "https://jsonplaceholder.typicode.com/posts/1",
"headers": { "Accept": "application/json" },
"params": { "userId": "1" },
"data": null
}
]
}
}Import Command:
mc-api-cli import -f ./collection.jsonThen load the collection in the UI:
mc-api-cli request -c TestCollection -p 3001Configuration
- Authentication Data: Stored in
~/.mc-api-cli/auth.json. - Collections: Stored in
~/.mc-api-cli/collections.json. - Directory Creation: The
~/.mc-api-cli/directory is automatically created on first use.
To clear authentication data:
mc-api-cli auth -u <username> # Re-authenticate
# Or manually delete ~/.mc-api-cli/auth.jsonTroubleshooting
Salesforce CLI Not Found:
- Install the Salesforce CLI:
npm install @salesforce/cli --global - Verify with
sf --version.
- Install the Salesforce CLI:
No Authorized Orgs Found:
- Authorize the org:
sf org login web -a <username>
- Authorize the org:
Port in Use:
- If
Port 3000 is already in use, use a different port:mc-api-cli request -p 3001 - Find and kill processes using the port:
lsof -i :3000 kill -9 <pid>
- If
UI Not Loading:
- Manually open
http://localhost:<port>in your browser. - Check console output for errors.
- Manually open
Response Issues:
- JSON responses appear in the Editor with an "Export JSON" button.
- CSV or JSON array responses display in a DataTable with a CSV export option.
