2 Commits

Author SHA1 Message Date
Morten Olsen
b308c7f9fe fix: align yaml option with documentation 2025-05-18 22:36:25 +02:00
Morten Olsen
ba56b66222 fix: yaml parsing 2025-05-18 22:29:50 +02:00
3 changed files with 14 additions and 7 deletions

View File

@@ -89,7 +89,7 @@ _(Note: Actual headers and some response fields might vary.)_
HTTP requests are defined in fenced code blocks annotated with `http`. The syntax is similar to the raw HTTP format: HTTP requests are defined in fenced code blocks annotated with `http`. The syntax is similar to the raw HTTP format:
```http disable ```
<METHOD> <URL> <METHOD> <URL>
<Header-Name>: <Header-Value> <Header-Name>: <Header-Value>
... ...
@@ -132,10 +132,17 @@ You can assign a unique ID to an `http` request block. This allows you to:
1. Reference its specific response in a `::response` directive. 1. Reference its specific response in a `::response` directive.
2. Access its request and response data in [Templating](https://www.google.com/search?q=%23templating-with-handlebars) via the `requests` and `responses` dictionaries. 2. Access its request and response data in [Templating](https://www.google.com/search?q=%23templating-with-handlebars) via the `requests` and `responses` dictionaries.
To add an ID, include `id=yourUniqueId` in the `http` block's info string: To add an ID, include `#yourUniqueId` or `id=yourUniqueId` in the `http` block's info string:
::raw-md[./examples/with-multiple-requests.md] ::raw-md[./examples/with-multiple-requests.md]
<details>
<summary>Output</summary>
::raw-md[./examples/with-multiple-requests.md]{render}
</details>
## Templating with Handlebars ## Templating with Handlebars
`http.md` uses [Handlebars](https://handlebarsjs.com/) for templating, allowing you to create dynamic content within your markdown files. You can inject data from request responses, input variables, and other requests into your HTTP blocks or general markdown text. `http.md` uses [Handlebars](https://handlebarsjs.com/) for templating, allowing you to create dynamic content within your markdown files. You can inject data from request responses, input variables, and other requests into your HTTP blocks or general markdown text.

View File

@@ -2,16 +2,16 @@
First, create a resource: First, create a resource:
```http id=createUser ```http #createUser,yaml,json
POST https://httpbin.org/post POST https://httpbin.org/post
Content-Type: application/json Content-Type: application/json
{"username": "alpha"} username: alpha
``` ```
Then, fetch a different resource: Then, fetch a different resource:
```http id=getItem ```http #getItem
GET https://httpbin.org/get?item=123 GET https://httpbin.org/get?item=123
``` ```

View File

@@ -44,7 +44,7 @@ const httpHandler: ExecutionHandler = ({
); );
let parsedBody = body; let parsedBody = body;
if (options.format === 'yaml') { if (options.yaml) {
try { try {
const parsed = YAML.parse(body); const parsed = YAML.parse(body);
parsedBody = JSON.stringify(parsed); parsedBody = JSON.stringify(parsed);
@@ -69,7 +69,7 @@ const httpHandler: ExecutionHandler = ({
} }
} }
node.value = content; node.value = [head, parsedBody].filter(Boolean).join('\n\n');
node.meta = undefined; node.meta = undefined;
context.addRequest({ context.addRequest({