mirror of
https://github.com/morten-olsen/http.md.git
synced 2026-02-08 00:46:28 +01:00
Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5d485acc97 | ||
|
|
68f5025527 | ||
|
|
a9a7bae28f | ||
|
|
b800290d72 | ||
|
|
d7b6a3880e |
7
.github/workflows/main.yaml
vendored
7
.github/workflows/main.yaml
vendored
@@ -92,7 +92,7 @@ jobs:
|
||||
|
||||
release:
|
||||
permissions:
|
||||
contents: read
|
||||
contents: write
|
||||
packages: write
|
||||
attestations: write
|
||||
id-token: write
|
||||
@@ -135,3 +135,8 @@ jobs:
|
||||
pnpm publish --no-git-checks --access public
|
||||
env:
|
||||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||
|
||||
- uses: stefanzweifel/git-auto-commit-action@v5
|
||||
with:
|
||||
commit_message: "docs: generated README"
|
||||
file_pattern: "*.md"
|
||||
|
||||
@@ -110,9 +110,9 @@ HTTP/200 OK
|
||||
access-control-allow-credentials: true
|
||||
access-control-allow-origin: *
|
||||
connection: keep-alive
|
||||
content-length: 559
|
||||
content-length: 556
|
||||
content-type: application/json
|
||||
date: Sun, 18 May 2025 18:31:46 GMT
|
||||
date: Sun, 18 May 2025 18:55:55 GMT
|
||||
server: gunicorn/19.9.0
|
||||
|
||||
{
|
||||
@@ -129,12 +129,12 @@ server: gunicorn/19.9.0
|
||||
"Host": "httpbin.org",
|
||||
"Sec-Fetch-Mode": "cors",
|
||||
"User-Agent": "node",
|
||||
"X-Amzn-Trace-Id": "Root=1-682a2792-7df702ce77a3b3696937eaeb"
|
||||
"X-Amzn-Trace-Id": "Root=1-682a2d3b-244883ec40275d5e642566d6"
|
||||
},
|
||||
"json": {
|
||||
"greeting": "Hello, http.md!"
|
||||
},
|
||||
"origin": "185.181.220.204",
|
||||
"origin": "13.64.151.43",
|
||||
"url": "https://httpbin.org/post"
|
||||
}
|
||||
|
||||
|
||||
@@ -176,6 +176,13 @@ Within your markdown document, the following variables are available in the Hand
|
||||
|
||||
::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.)_
|
||||
|
||||
**2. Displaying a status code in markdown text:**
|
||||
|
||||
@@ -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:
|
||||
|
||||
|
||||
@@ -16,6 +16,11 @@ const httpHandler: ExecutionHandler = ({
|
||||
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({
|
||||
type: 'http',
|
||||
@@ -28,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) => {
|
||||
@@ -66,7 +72,7 @@ const httpHandler: ExecutionHandler = ({
|
||||
node.meta = undefined;
|
||||
|
||||
context.addRequest({
|
||||
id: options.id?.toString(),
|
||||
id,
|
||||
request: {
|
||||
method,
|
||||
url,
|
||||
|
||||
Reference in New Issue
Block a user