diff --git a/README.md b/README.md
index 2e6b16b..2a326d0 100644
--- a/README.md
+++ b/README.md
@@ -2,33 +2,35 @@
**`http.md` is a powerful tool that transforms your markdown files into living, executable API documentation and testing suites. Write your HTTP requests directly within markdown, see their responses, and use templating to build dynamic examples and test flows.**
-It allows developers to create API documentation that is always accurate and up-to-date because the documentation itself *is* the set of executable requests. This ensures that your examples work and your tests run directly from the documents you share.
+It allows developers to create API documentation that is always accurate and up-to-date because the documentation itself _is_ the set of executable requests. This ensures that your examples work and your tests run directly from the documents you share.
## Key Features
-* **Markdown-Native:** Define HTTP requests using familiar markdown code blocks.
-* **Live Requests:** Execute requests and embed their responses directly into your documentation.
-* **Templating:** Use Handlebars syntax to chain requests, extract data from responses, and use external inputs.
-* **File Embedding:** Include and reuse requests from other markdown files.
-* **Terminal & File Output:** View live previews in your terminal or build static markdown files for sharing or static site generation.
-* **Watch Mode:** Automatically re-render documents on file changes for a fast development loop.
-* **Flexible Configuration:** Control request execution, output formatting, and visibility.
+- **Markdown-Native:** Define HTTP requests using familiar markdown code blocks.
+- **Live Requests:** Execute requests and embed their responses directly into your documentation.
+- **Templating:** Use Handlebars syntax to chain requests, extract data from responses, and use external inputs.
+- **File Embedding:** Include and reuse requests from other markdown files.
+- **Terminal & File Output:** View live previews in your terminal or build static markdown files for sharing or static site generation.
+- **Watch Mode:** Automatically re-render documents on file changes for a fast development loop.
+- **Flexible Configuration:** Control request execution, output formatting, and visibility.
## Use Cases
-* **API Documentation:** Create clear, executable examples that users can trust.
-* **Integration Testing:** Write simple integration test suites that verify API behavior.
-* **Tutorials & Guides:** Build step-by-step guides where each HTTP interaction is shown with its real output.
-* **Rapid Prototyping:** Quickly experiment with APIs and document your findings.
+- **API Documentation:** Create clear, executable examples that users can trust.
+- **Integration Testing:** Write simple integration test suites that verify API behavior.
+- **Tutorials & Guides:** Build step-by-step guides where each HTTP interaction is shown with its real output.
+- **Rapid Prototyping:** Quickly experiment with APIs and document your findings.
## Installation
Install `http.md` globally using npm:
```shell
-npm i -g @morten-olsen/httpmd
+npm i -g http.md
```
+Or use `npx http.md` instead of `http.md`
+
## Getting Started
### Your First Request
@@ -52,7 +54,6 @@ Content-Type: application/json
And here is the response:
::response
-
````
### Rendering Documents
@@ -63,13 +64,13 @@ You have two primary ways to render your `http.md` file:
For a development server that outputs to your terminal and watches for changes:
```shell
- httpmd dev example.md
+ http.md dev example.md
```
With watch mode:
```shell
- httpmd dev --watch example.md
+ http.md dev --watch example.md
```
This command will process `example.md`, execute the HTTP requests, and print the resulting markdown (with responses filled in) to the terminal. With `--watch`, any changes to `example.md` will trigger a re-run.
@@ -78,13 +79,13 @@ You have two primary ways to render your `http.md` file:
To generate a new markdown file with the responses and templated values rendered:
```shell
- httpmd build example.md output.md
+ http.md build example.md output.md
```
With watch mode:
```shell
- httpmd build --watch example.md output.md
+ http.md build --watch example.md output.md
```
This creates `output.md`, which is a static snapshot of `example.md` after all requests have been executed and templating applied. This file is suitable for version control, sharing, or integration with static site generators.
@@ -116,33 +117,32 @@ date: Sun, 18 May 2025 19:12:17 GMT
server: gunicorn/19.9.0
{
- "args": {},
- "data": "{\"greeting\": \"Hello, http.md!\"}",
- "files": {},
- "form": {},
+ "args": {},
+ "data": "{\"greeting\": \"Hello, http.md!\"}",
+ "files": {},
+ "form": {},
"headers": {
- "Accept": "*/*",
- "Accept-Encoding": "br, gzip, deflate",
- "Accept-Language": "*",
- "Content-Length": "31",
- "Content-Type": "application/json",
- "Host": "httpbin.org",
- "Sec-Fetch-Mode": "cors",
- "User-Agent": "node",
+ "Accept": "*/*",
+ "Accept-Encoding": "br, gzip, deflate",
+ "Accept-Language": "*",
+ "Content-Length": "31",
+ "Content-Type": "application/json",
+ "Host": "httpbin.org",
+ "Sec-Fetch-Mode": "cors",
+ "User-Agent": "node",
"X-Amzn-Trace-Id": "Root=1-682a3111-131bcbff690b03fd64aa4617"
- },
+ },
"json": {
"greeting": "Hello, http.md!"
- },
- "origin": "23.96.180.7",
+ },
+ "origin": "23.96.180.7",
"url": "https://httpbin.org/post"
}
```
-
````
-*(Note: Actual headers and some response fields might vary.)*
+_(Note: Actual headers and some response fields might vary.)_
## Core Concepts
@@ -183,8 +183,8 @@ All requests in a document are executed sequentially from top to bottom by defau
The `::response` directive is used to render the full HTTP response (status line, headers, and body) of an HTTP request.
-* **Implicit Last:** If used without any arguments (i.e., `::response`), it renders the response of the most recently defined `http` block above it.
-* **Explicit by ID:** You can render the response of a specific request by referencing its ID (see [Request IDs](https://www.google.com/search?q=%23request-ids)).
+- **Implicit Last:** If used without any arguments (i.e., `::response`), it renders the response of the most recently defined `http` block above it.
+- **Explicit by ID:** You can render the response of a specific request by referencing its ID (see [Request IDs](https://www.google.com/search?q=%23request-ids)).
### Request IDs
@@ -218,7 +218,6 @@ Response from creating the user:
Response from getting the item:
::response{#getItem}
-
````
## Templating with Handlebars
@@ -231,33 +230,33 @@ Templating syntax uses double curly braces: `{{expression}}`.
Within your markdown document, the following variables are available in the Handlebars context:
-* **`request`** (Object): Details of the most recently processed HTTP request *before* it's sent.
+- **`request`** (Object): Details of the most recently processed HTTP request _before_ it's sent.
- * `request.method` (String): The HTTP method (e.g., "GET", "POST").
- * `request.url` (String): The request URL.
- * `request.headers` (Object): An object containing request headers.
- * `request.body` (String): The raw request body.
+ - `request.method` (String): The HTTP method (e.g., "GET", "POST").
+ - `request.url` (String): The request URL.
+ - `request.headers` (Object): An object containing request headers.
+ - `request.body` (String): The raw request body.
-* **`response`** (Object): Details of the most recently received HTTP response.
+- **`response`** (Object): Details of the most recently received HTTP response.
- * `response.status` (Number): The HTTP status code (e.g., 200, 404).
- * `response.statusText` (String): The HTTP status message (e.g., "OK", "Not Found").
- * `response.headers` (Object): An object containing response headers.
- * `response.body` (String/Object): The response body. If the `http` block had the `json` option and the response was valid JSON, this will be a parsed JSON object. Otherwise, it's a raw string.
- * `response.rawBody` (String): The raw response body as a string, regardless of parsing.
- * *(In case of network errors or non-HTTP errors, `status` and `body` might reflect error information.)*
+ - `response.status` (Number): The HTTP status code (e.g., 200, 404).
+ - `response.statusText` (String): The HTTP status message (e.g., "OK", "Not Found").
+ - `response.headers` (Object): An object containing response headers.
+ - `response.body` (String/Object): The response body. If the `http` block had the `json` option and the response was valid JSON, this will be a parsed JSON object. Otherwise, it's a raw string.
+ - `response.rawBody` (String): The raw response body as a string, regardless of parsing.
+ - _(In case of network errors or non-HTTP errors, `status` and `body` might reflect error information.)_
-* **`requests`** (Object): A dictionary mapping request IDs to their respective `request` objects (as defined above).
+- **`requests`** (Object): A dictionary mapping request IDs to their respective `request` objects (as defined above).
- * Example: `{{requests.createUser.url}}`
+ - Example: `{{requests.createUser.url}}`
-* **`responses`** (Object): A dictionary mapping request IDs to their respective `response` objects (as defined above).
+- **`responses`** (Object): A dictionary mapping request IDs to their respective `response` objects (as defined above).
- * Example: `{{responses.createUser.status}}`, `{{responses.createUser.body.id}}` (if `body` is a parsed JSON object).
+ - Example: `{{responses.createUser.status}}`, `{{responses.createUser.body.id}}` (if `body` is a parsed JSON object).
-* **`input`** (Object): A dictionary of variables passed to `http.md` via the command line using the `-i` or `--input` flag.
+- **`input`** (Object): A dictionary of variables passed to `http.md` via the command line using the `-i` or `--input` flag.
- * Example: If you run `httpmd dev -i userId=123 -i apiKey=secret myfile.md`, you can use `{{input.userId}}` and `{{input.apiKey}}`.
+ - Example: If you run `http.md dev -i userId=123 -i apiKey=secret myfile.md`, you can use `{{input.userId}}` and `{{input.apiKey}}`.
### Templating Examples
@@ -280,7 +279,6 @@ GET https://httpbin.org/anything/{{responses.createItem.body.json.name}}
```
::response{#fetchItem}
-
````
@@ -313,32 +311,31 @@ date: Sun, 18 May 2025 19:12:18 GMT
server: gunicorn/19.9.0
{
- "args": {},
- "data": "",
- "files": {},
- "form": {},
+ "args": {},
+ "data": "",
+ "files": {},
+ "form": {},
"headers": {
- "Accept": "*/*",
- "Accept-Encoding": "br, gzip, deflate",
- "Accept-Language": "*",
- "Host": "httpbin.org",
- "Sec-Fetch-Mode": "cors",
- "User-Agent": "node",
+ "Accept": "*/*",
+ "Accept-Encoding": "br, gzip, deflate",
+ "Accept-Language": "*",
+ "Host": "httpbin.org",
+ "Sec-Fetch-Mode": "cors",
+ "User-Agent": "node",
"X-Amzn-Trace-Id": "Root=1-682a3112-4bbb29111129c1556c487ca1"
- },
- "json": null,
- "method": "GET",
- "origin": "23.96.180.7",
+ },
+ "json": null,
+ "method": "GET",
+ "origin": "23.96.180.7",
"url": "https://httpbin.org/anything/My New Item"
}
```
-
````
-*(Note: `httpbin.org/post` wraps the JSON sent in a "json" field in its response. If your API returns the ID directly at the root of the JSON body, you'd use `{{responses.createItem.body.id}}` assuming the `createItem` request had the `json` option.)*
+_(Note: `httpbin.org/post` wraps the JSON sent in a "json" field in its response. If your API returns the ID directly at the root of the JSON body, you'd use `{{responses.createItem.body.id}}` assuming the `createItem` request had the `json` option.)_
**2. Displaying a status code in markdown text:**
@@ -347,7 +344,7 @@ server: gunicorn/19.9.0
GET https://httpbin.org/status/201
```
-The request to `/status/201` completed with status code: ****.
+The request to `/status/201` completed with status code: \*\*\*\*.
````
## Managing Documents
@@ -379,7 +376,7 @@ Let's include some shared requests:
::md[./_shared_requests.md]
-The shared GET request returned:
+The shared GET request returned:
Now, a request specific to this document:
@@ -404,7 +401,7 @@ You can pass external data into your `http.md` documents using the `-i` (or `--i
**CLI Command:**
```shell
-httpmd build mydoc.md output.md -i baseUrl=https://api.production.example.com -i apiKey=YOUR_SECRET_KEY
+http.md build mydoc.md output.md -i baseUrl=https://api.production.example.com -i apiKey=YOUR_SECRET_KEY
```
**Markdown Usage (`mydoc.md`):**
@@ -412,7 +409,7 @@ httpmd build mydoc.md output.md -i baseUrl=https://api.production.example.com -i
````markdown
```http
GET /users/1
-Authorization: Bearer
+Authorization: Bearer
```
::response
@@ -424,17 +421,17 @@ Authorization: Bearer
You can configure the behavior of each `http` code block by adding options to its info string, separated by commas.
-* `id={your-id}`: Assigns a unique ID to the request. This ID can be used to reference the request's response in the `::response` directive and in templating variables (`requests.your-id`, `responses.your-id`).
+- `id={your-id}`: Assigns a unique ID to the request. This ID can be used to reference the request's response in the `::response` directive and in templating variables (`requests.your-id`, `responses.your-id`).
- * Example: ` ```http id=getUser,json `
+ - Example: ` ```http id=getUser,json `
-* `json`: If present, `http.md` will attempt to parse the **response body** as JSON. If successful, `response.body` (and `responses.id.body`) will be the parsed JavaScript object/array, making it easier to access its properties in templates (e.g., `{{response.body.fieldName}}`).
+- `json`: If present, `http.md` will attempt to parse the **response body** as JSON. If successful, `response.body` (and `responses.id.body`) will be the parsed JavaScript object/array, making it easier to access its properties in templates (e.g., `{{response.body.fieldName}}`).
- * Example: ` ```http json `
+ - Example: ` ```http json `
-* `yaml`: If present, the **request body** written in YAML format within the code block will be automatically converted to JSON before the request is sent. This allows for writing complex request bodies in a more human-readable YAML syntax. You should still set the `Content-Type` header appropriately (e.g., to `application/json`) if the server expects JSON.
+- `yaml`: If present, the **request body** written in YAML format within the code block will be automatically converted to JSON before the request is sent. This allows for writing complex request bodies in a more human-readable YAML syntax. You should still set the `Content-Type` header appropriately (e.g., to `application/json`) if the server expects JSON.
- * Example:
+ - Example:
````markdown
```http yaml
@@ -449,20 +446,20 @@ You can configure the behavior of each `http` code block by adding options to it
```
````
-* `disable`: If present, the HTTP request will **not** be executed. No actual network call will be made. The corresponding `response` variable will be undefined or empty, and `::response` will typically render a "Request disabled" message or similar.
+- `disable`: If present, the HTTP request will **not** be executed. No actual network call will be made. The corresponding `response` variable will be undefined or empty, and `::response` will typically render a "Request disabled" message or similar.
- * Example: ` ```http disable `
+ - Example: ` ```http disable `
-* `hidden`: If present, the `http` code block itself will **not be included** in the rendered output document. However, the request *is still made* (unless `disable` is also specified), and its response data can be used in templates or displayed with an explicit `::response{#id}` directive. This is useful for prerequisite requests (like authentication) whose details you don't want to clutter the main documentation.
+- `hidden`: If present, the `http` code block itself will **not be included** in the rendered output document. However, the request _is still made_ (unless `disable` is also specified), and its response data can be used in templates or displayed with an explicit `::response{#id}` directive. This is useful for prerequisite requests (like authentication) whose details you don't want to clutter the main documentation.
- * Example: ` ```http id=authRequest,hidden `
+ - Example: ` ```http id=authRequest,hidden `
**Combined Example:**
````markdown
```http id=complexRequest,json,yaml,hidden
POST /data
-X-API-Key:
+X-API-Key:
Content-Type: application/json
# Request body written in YAML, will be converted to JSON
@@ -481,12 +478,12 @@ Directives can also have options, specified similarly.
#### `::response` Directive Options
-* `id={id}` (or `#{id}` as a shorthand): Renders the output of a specific request identified by `{id}`.
- * Example: `::response{#getUser}` or `::response{id=getUser}`
-* `yaml`: Renders the (typically JSON) response body formatted as YAML. This is for display purposes.
- * Example: `::response{yaml}`
-* `truncate={chars}`: Truncates the displayed **response body** to the specified number of characters. Headers and status line are not affected.
- * Example: `::response{truncate=100}`
+- `id={id}` (or `#{id}` as a shorthand): Renders the output of a specific request identified by `{id}`.
+ - Example: `::response{#getUser}` or `::response{id=getUser}`
+- `yaml`: Renders the (typically JSON) response body formatted as YAML. This is for display purposes.
+ - Example: `::response{yaml}`
+- `truncate={chars}`: Truncates the displayed **response body** to the specified number of characters. Headers and status line are not affected.
+ - Example: `::response{truncate=100}`
**Combined Example for `::response`:**
`::response{#getUser,yaml,truncate=500}` - Displays the response for request `getUser`, formats its body as YAML, and truncates the body display to 500 characters.
@@ -495,52 +492,52 @@ Directives can also have options, specified similarly.
The `::md` directive embeds another markdown document.
-* **File Path:** The first argument (required) is the path to the markdown file to embed.
- * Example: `::md[./includes/authentication.md]`
-* `hidden`: If present, the actual content (markdown) of the embedded document will not be rendered in the output. However, any `http` requests within the embedded document *are still processed*, and their `request` and `response` data become available in the parent document's templating context (via `requests.id` and `responses.id`). This is useful if you only want to execute the requests from an included file (e.g., a common setup sequence) and use their results, without displaying the embedded file's content.
- * Example: `::md[./setup_requests.md]{hidden}`
+- **File Path:** The first argument (required) is the path to the markdown file to embed.
+ - Example: `::md[./includes/authentication.md]`
+- `hidden`: If present, the actual content (markdown) of the embedded document will not be rendered in the output. However, any `http` requests within the embedded document _are still processed_, and their `request` and `response` data become available in the parent document's templating context (via `requests.id` and `responses.id`). This is useful if you only want to execute the requests from an included file (e.g., a common setup sequence) and use their results, without displaying the embedded file's content.
+ - Example: `::md[./setup_requests.md]{hidden}`
#### `::input[{name}]` Directive Options
The `::input` directive is used to declare expected input variables
-* **Variable Name:** The first argument (required) is the name of the variable
- * Example: `::input[myVariable]` will define `input.myVariable`
-* `required`: If present it will require that the variable is provided
-* `default={value}`: Defines the default value if no value has been provided
-* `format=string|number|bool|json|date`: If provided the value will be parsed using the specified format
-* \`\`
+- **Variable Name:** The first argument (required) is the name of the variable
+ - Example: `::input[myVariable]` will define `input.myVariable`
+- `required`: If present it will require that the variable is provided
+- `default={value}`: Defines the default value if no value has been provided
+- `format=string|number|bool|json|date`: If provided the value will be parsed using the specified format
+- \`\`
## Command-Line Interface (CLI)
-The `httpmd` tool provides the following commands:
+The `http.md` tool provides the following commands:
-### `httpmd dev `
+### `http.md dev `
Processes the ``, executes all HTTP requests, resolves templates, and prints the resulting markdown to the **terminal (stdout)**.
-* **Purpose:** Useful for live development and quick previews.
-* **Options:**
- * `--watch`: Monitors the `` (and any embedded files) for changes. On detection of a change, it automatically re-processes and re-renders the output to the terminal.
- * `-i `, `--input `: Defines an input variable for templating (see [Using Input Variables](https://www.google.com/search?q=%23using-input-variables)). Can be specified multiple times for multiple variables.
+- **Purpose:** Useful for live development and quick previews.
+- **Options:**
+ - `--watch`: Monitors the `` (and any embedded files) for changes. On detection of a change, it automatically re-processes and re-renders the output to the terminal.
+ - `-i `, `--input `: Defines an input variable for templating (see [Using Input Variables](https://www.google.com/search?q=%23using-input-variables)). Can be specified multiple times for multiple variables.
**Example:**
```shell
-httpmd dev api_tests.md --watch -i host=localhost:3000
+http.md dev api_tests.md --watch -i host=localhost:3000
```
-### `httpmd build `
+### `http.md build `
Processes the ``, executes all HTTP requests, resolves templates, and saves the resulting markdown to ``.
-* **Purpose:** Generates a static, shareable markdown file with all dynamic content resolved. Ideal for version control, static site generation, or distributing documentation.
-* **Options:**
- * `--watch`: Monitors the `` (and any embedded files) for changes. On detection of a change, it automatically re-processes and re-builds the ``.
- * `-i `, `--input `: Defines an input variable for templating.
+- **Purpose:** Generates a static, shareable markdown file with all dynamic content resolved. Ideal for version control, static site generation, or distributing documentation.
+- **Options:**
+ - `--watch`: Monitors the `` (and any embedded files) for changes. On detection of a change, it automatically re-processes and re-builds the ``.
+ - `-i `, `--input `: Defines an input variable for templating.
**Example:**
```shell
-httpmd build official_api_docs.md public/api_docs_v1.md -i version=v1.0
+http.md build official_api_docs.md public/api_docs_v1.md -i version=v1.0
```
diff --git a/docs/README.md b/docs/README.md
index 7cdfda7..ca1b09a 100644
--- a/docs/README.md
+++ b/docs/README.md
@@ -30,7 +30,7 @@ It allows developers to create API documentation that is always accurate and up-
Install `http.md` globally using npm:
```shell
-npm i -g @morten-olsen/httpmd
+npm i -g @morten-olsen/http.md
```
## Getting Started
@@ -51,13 +51,13 @@ You have two primary ways to render your `http.md` file:
For a development server that outputs to your terminal and watches for changes:
```shell
- httpmd dev example.md
+ http.md dev example.md
```
With watch mode:
```shell
- httpmd dev --watch example.md
+ http.md dev --watch example.md
```
This command will process `example.md`, execute the HTTP requests, and print the resulting markdown (with responses filled in) to the terminal. With `--watch`, any changes to `example.md` will trigger a re-run.
@@ -66,13 +66,13 @@ You have two primary ways to render your `http.md` file:
To generate a new markdown file with the responses and templated values rendered:
```shell
- httpmd build example.md output.md
+ http.md build example.md output.md
```
With watch mode:
```shell
- httpmd build --watch example.md output.md
+ http.md build --watch example.md output.md
```
This creates `output.md`, which is a static snapshot of `example.md` after all requests have been executed and templating applied. This file is suitable for version control, sharing, or integration with static site generators.
@@ -179,7 +179,7 @@ Within your markdown document, the following variables are available in the Hand
- **`input`** (Object): A dictionary of variables passed to `http.md` via the command line using the `-i` or `--input` flag.
- - Example: If you run `httpmd dev -i userId=123 -i apiKey=secret myfile.md`, you can use `{{input.userId}}` and `{{input.apiKey}}`.
+ - Example: If you run `http.md dev -i userId=123 -i apiKey=secret myfile.md`, you can use `{{input.userId}}` and `{{input.apiKey}}`.
### Templating Examples
@@ -244,7 +244,7 @@ You can pass external data into your `http.md` documents using the `-i` (or `--i
**CLI Command:**
```shell
-httpmd build mydoc.md output.md -i baseUrl=https://api.production.example.com -i apiKey=YOUR_SECRET_KEY
+http.md build mydoc.md output.md -i baseUrl=https://api.production.example.com -i apiKey=YOUR_SECRET_KEY
```
**Markdown Usage (`mydoc.md`):**
@@ -353,9 +353,9 @@ The `::input` directive is used to declare expected input variables
## Command-Line Interface (CLI)
-The `httpmd` tool provides the following commands:
+The `http.md` tool provides the following commands:
-### `httpmd dev `
+### `http.md dev `
Processes the ``, executes all HTTP requests, resolves templates, and prints the resulting markdown to the **terminal (stdout)**.
@@ -367,10 +367,10 @@ Processes the ``, executes all HTTP requests, resolves templates
**Example:**
```shell
-httpmd dev api_tests.md --watch -i host=localhost:3000
+http.md dev api_tests.md --watch -i host=localhost:3000
```
-### `httpmd build `
+### `http.md build `
Processes the ``, executes all HTTP requests, resolves templates, and saves the resulting markdown to ``.
@@ -382,5 +382,5 @@ Processes the ``, executes all HTTP requests, resolves templates
**Example:**
```shell
-httpmd build official_api_docs.md public/api_docs_v1.md -i version=v1.0
+http.md build official_api_docs.md public/api_docs_v1.md -i version=v1.0
```
diff --git a/package.json b/package.json
index 908e852..b999c82 100644
--- a/package.json
+++ b/package.json
@@ -1,11 +1,11 @@
{
- "name": "@morten-olsen/httpmd",
+ "name": "@morten-olsen/http.md",
"version": "1.0.0",
"description": "",
"main": "dist/exports.js",
"type": "module",
"bin": {
- "httpmd": "./bin/cli.mjs"
+ "http.md": "./bin/cli.mjs"
},
"files": [
"dist",