diff --git a/docs/README.md b/docs/README.md index cac6ae9..62190d9 100644 --- a/docs/README.md +++ b/docs/README.md @@ -176,6 +176,13 @@ Within your markdown document, the following variables are available in the Hand ::raw-md[./examples/with-template.md] +
+ Output + +::raw-md[./examples/with-template.md]{render} + +
+ _(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:** diff --git a/docs/examples/with-template.md b/docs/examples/with-template.md index 44dd012..1c7c586 100644 --- a/docs/examples/with-template.md +++ b/docs/examples/with-template.md @@ -1,11 +1,11 @@ -```http id=createItem json +```http #createItem,json POST https://httpbin.org/post Content-Type: application/json {"name": "My New Item"} ``` -The new item ID is: {{responses.createItem.body.json.name}} +The new item ID is: {{response.body.json.name}} Now, let's fetch the item using a (mocked) ID from the response: diff --git a/src/execution/handlers/handlers.http.ts b/src/execution/handlers/handlers.http.ts index be36974..3c371b7 100644 --- a/src/execution/handlers/handlers.http.ts +++ b/src/execution/handlers/handlers.http.ts @@ -33,7 +33,8 @@ const httpHandler: ExecutionHandler = ({ const content = template(context); const [head, body] = content.split('\n\n'); const [top, ...headerItems] = head.split('\n'); - const [method, url] = top.split(' '); + const [method, ...urlParts] = top.split(' '); + const url = urlParts.join(' ').trim(); const headers = Object.fromEntries( headerItems.map((header) => {