mirror of
https://github.com/morten-olsen/http.md.git
synced 2026-02-08 00:46:28 +01:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6ce6eeeedb | ||
|
|
ad342e5f10 |
67
README.md
67
README.md
@@ -110,9 +110,9 @@ HTTP/200 OK
|
||||
access-control-allow-credentials: true
|
||||
access-control-allow-origin: *
|
||||
connection: keep-alive
|
||||
content-length: 556
|
||||
content-length: 555
|
||||
content-type: application/json
|
||||
date: Sun, 18 May 2025 18:55:55 GMT
|
||||
date: Sun, 18 May 2025 19:12:17 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-682a2d3b-244883ec40275d5e642566d6"
|
||||
"X-Amzn-Trace-Id": "Root=1-682a3111-131bcbff690b03fd64aa4617"
|
||||
},
|
||||
"json": {
|
||||
"greeting": "Hello, http.md!"
|
||||
},
|
||||
"origin": "13.64.151.43",
|
||||
"origin": "23.96.180.7",
|
||||
"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:**
|
||||
|
||||
````markdown
|
||||
```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:
|
||||
|
||||
@@ -283,6 +283,61 @@ 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.)*
|
||||
|
||||
**2. Displaying a status code in markdown text:**
|
||||
|
||||
@@ -209,34 +209,18 @@ The requests from the embedded document are processed, and their `request` and `
|
||||
|
||||
Assume `_shared_requests.md` contains:
|
||||
|
||||
````markdown
|
||||
```http id=sharedGetRequest
|
||||
GET https://httpbin.org/get
|
||||
```
|
||||
````
|
||||
::raw-md[./examples/_shared_requests.md]
|
||||
|
||||
Then, in `main.md`:
|
||||
|
||||
````markdown
|
||||
# Main Document
|
||||
::raw-md[./examples/with-template.md]
|
||||
|
||||
Let's include some shared requests:
|
||||
<details>
|
||||
<summary>Output</summary>
|
||||
|
||||
::md[./_shared_requests.md]
|
||||
::raw-md[./examples/with-template.md]{render}
|
||||
|
||||
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
|
||||
````
|
||||
</details>
|
||||
|
||||
When `main.md` is processed, `_shared_requests.md` will be embedded, its `sharedGetRequest` will be executed, and its data will be available for templating.
|
||||
|
||||
|
||||
3
docs/examples/_shared_requests.md
Normal file
3
docs/examples/_shared_requests.md
Normal file
@@ -0,0 +1,3 @@
|
||||
```http #sharedGetRequest
|
||||
GET https://httpbin.org/get
|
||||
```
|
||||
18
docs/examples/with-shared_requests.md
Normal file
18
docs/examples/with-shared_requests.md
Normal file
@@ -0,0 +1,18 @@
|
||||
# Main Document
|
||||
|
||||
Let's include some shared requests:
|
||||
|
||||
::md[./_shared_requests.md]
|
||||
|
||||
The shared GET request returned:
|
||||
|
||||
Now, a request specific to this document:
|
||||
|
||||
```http
|
||||
POST https://httpbin.org/post
|
||||
Content-Type: application/json
|
||||
|
||||
{"dataFromMain": "someValue", "sharedUrl": ""}
|
||||
```
|
||||
|
||||
::response
|
||||
Reference in New Issue
Block a user