1 Commits

Author SHA1 Message Date
Morten Olsen
2a2f2f5627 feat: load env vars 2025-05-18 20:34:51 +02:00
8 changed files with 34 additions and 115 deletions

View File

@@ -92,7 +92,7 @@ jobs:
release: release:
permissions: permissions:
contents: write contents: read
packages: write packages: write
attestations: write attestations: write
id-token: write id-token: write
@@ -135,8 +135,3 @@ jobs:
pnpm publish --no-git-checks --access public pnpm publish --no-git-checks --access public
env: env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- uses: stefanzweifel/git-auto-commit-action@v5
with:
commit_message: "docs: generated README"
file_pattern: "*.md"

View File

@@ -110,9 +110,9 @@ HTTP/200 OK
access-control-allow-credentials: true access-control-allow-credentials: true
access-control-allow-origin: * access-control-allow-origin: *
connection: keep-alive connection: keep-alive
content-length: 555 content-length: 559
content-type: application/json content-type: application/json
date: Sun, 18 May 2025 19:12:17 GMT date: Sun, 18 May 2025 18:31:46 GMT
server: gunicorn/19.9.0 server: gunicorn/19.9.0
{ {
@@ -129,12 +129,12 @@ server: gunicorn/19.9.0
"Host": "httpbin.org", "Host": "httpbin.org",
"Sec-Fetch-Mode": "cors", "Sec-Fetch-Mode": "cors",
"User-Agent": "node", "User-Agent": "node",
"X-Amzn-Trace-Id": "Root=1-682a3111-131bcbff690b03fd64aa4617" "X-Amzn-Trace-Id": "Root=1-682a2792-7df702ce77a3b3696937eaeb"
}, },
"json": { "json": {
"greeting": "Hello, http.md!" "greeting": "Hello, http.md!"
}, },
"origin": "23.96.180.7", "origin": "185.181.220.204",
"url": "https://httpbin.org/post" "url": "https://httpbin.org/post"
} }
@@ -264,14 +264,14 @@ Within your markdown document, the following variables are available in the Hand
**1. Using a value from a previous response in a new request:** **1. Using a value from a previous response in a new request:**
````markdown ````markdown
```http #createItem,json ```http id=createItem json
POST https://httpbin.org/post POST https://httpbin.org/post
Content-Type: application/json Content-Type: application/json
{"name": "My New Item"} {"name": "My New Item"}
``` ```
The new item ID is: {{response.body.json.name}} The new item ID is: {{responses.createItem.body.json.name}}
Now, let's fetch the item using a (mocked) ID from the response: Now, let's fetch the item using a (mocked) ID from the response:
@@ -283,61 +283,6 @@ GET https://httpbin.org/anything/{{responses.createItem.body.json.name}}
```` ````
<details>
<summary>Output</summary>
````markdown
```http
POST https://httpbin.org/post
Content-Type: application/json
{"name": "My New Item"}
```
The new item ID is: My New Item
Now, let's fetch the item using a (mocked) ID from the response:
```http
GET https://httpbin.org/anything/My New Item
```
```
HTTP/200 OK
access-control-allow-credentials: true
access-control-allow-origin: *
connection: keep-alive
content-length: 451
content-type: application/json
date: Sun, 18 May 2025 19:12:18 GMT
server: gunicorn/19.9.0
{
"args": {},
"data": "",
"files": {},
"form": {},
"headers": {
"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",
"url": "https://httpbin.org/anything/My New Item"
}
```
````
</details>
*(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:** **2. Displaying a status code in markdown text:**

View File

@@ -176,13 +176,6 @@ Within your markdown document, the following variables are available in the Hand
::raw-md[./examples/with-template.md] ::raw-md[./examples/with-template.md]
<details>
<summary>Output</summary>
::raw-md[./examples/with-template.md]{render}
</details>
_(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:** **2. Displaying a status code in markdown text:**
@@ -209,18 +202,34 @@ The requests from the embedded document are processed, and their `request` and `
Assume `_shared_requests.md` contains: Assume `_shared_requests.md` contains:
::raw-md[./examples/_shared_requests.md] ````markdown
```http id=sharedGetRequest
GET https://httpbin.org/get
```
````
Then, in `main.md`: Then, in `main.md`:
::raw-md[./examples/with-shared-requests.md] ````markdown
# Main Document
<details> Let's include some shared requests:
<summary>Output</summary>
::raw-md[./examples/with-shared-requests.md]{render} ::md[./_shared_requests.md]
</details> The shared GET request returned: {{responses.sharedGetRequest.status}}
Now, a request specific to this document:
```http
POST https://httpbin.org/post
Content-Type: application/json
{"dataFromMain": "someValue", "sharedUrl": "{{requests.sharedGetRequest.url}}"}
```
::response
````
When `main.md` is processed, `_shared_requests.md` will be embedded, its `sharedGetRequest` will be executed, and its data will be available for templating. When `main.md` is processed, `_shared_requests.md` will be embedded, its `sharedGetRequest` will be executed, and its data will be available for templating.

View File

@@ -1,3 +0,0 @@
```http #sharedGetRequest
GET https://httpbin.org/get
```

View File

@@ -1,18 +0,0 @@
# Main Document
Let's include some shared requests:
::md[./_shared_requests.md]
The shared GET request returned: {{response.statusText}}
Now, a request specific to this document:
```http
POST https://httpbin.org/post
Content-Type: application/json
{"dataFromMain": "someValue", "sharedUrl": "{{requests.sharedGetRequest.url}}"}
```
::response

View File

@@ -1,11 +1,11 @@
```http #createItem,json ```http id=createItem json
POST https://httpbin.org/post POST https://httpbin.org/post
Content-Type: application/json Content-Type: application/json
{"name": "My New Item"} {"name": "My New Item"}
``` ```
The new item ID is: {{response.body.json.name}} The new item ID is: {{responses.createItem.body.json.name}}
Now, let's fetch the item using a (mocked) ID from the response: Now, let's fetch the item using a (mocked) ID from the response:

View File

@@ -10,7 +10,6 @@ type Response = {
statusText: string; statusText: string;
headers: Record<string, string>; headers: Record<string, string>;
body?: string; body?: string;
rawBody?: string;
}; };
type AddRequestOptios = { type AddRequestOptios = {

View File

@@ -16,11 +16,6 @@ const httpHandler: ExecutionHandler = ({
return [key.trim(), value?.trim() || true]; return [key.trim(), value?.trim() || true];
}) })
); );
let id = options.id?.toString();
const idPart = optionParts.find((option) => option.startsWith('#'));
if (idPart) {
id = idPart.slice(1);
}
addStep({ addStep({
type: 'http', type: 'http',
@@ -33,8 +28,7 @@ const httpHandler: ExecutionHandler = ({
const content = template(context); const content = template(context);
const [head, body] = content.split('\n\n'); const [head, body] = content.split('\n\n');
const [top, ...headerItems] = head.split('\n'); const [top, ...headerItems] = head.split('\n');
const [method, ...urlParts] = top.split(' '); const [method, url] = top.split(' ');
const url = urlParts.join(' ').trim();
const headers = Object.fromEntries( const headers = Object.fromEntries(
headerItems.map((header) => { headerItems.map((header) => {
@@ -59,8 +53,7 @@ const httpHandler: ExecutionHandler = ({
body body
}); });
const rawBody = await response.text(); let responseText = await response.text();
let responseText = rawBody;
if (options.json) { if (options.json) {
try { try {
responseText = JSON.parse(responseText); responseText = JSON.parse(responseText);
@@ -73,7 +66,7 @@ const httpHandler: ExecutionHandler = ({
node.meta = undefined; node.meta = undefined;
context.addRequest({ context.addRequest({
id, id: options.id?.toString(),
request: { request: {
method, method,
url, url,
@@ -85,7 +78,6 @@ const httpHandler: ExecutionHandler = ({
statusText: response.statusText, statusText: response.statusText,
headers: Object.fromEntries(response.headers.entries()), headers: Object.fromEntries(response.headers.entries()),
body: responseText, body: responseText,
rawBody: rawBody,
}, },
}); });
}, },