mirror of
https://github.com/morten-olsen/http.md.git
synced 2026-02-08 00:46:28 +01:00
docs: improved docs
This commit is contained in:
@@ -209,34 +209,18 @@ The requests from the embedded document are processed, and their `request` and `
|
|||||||
|
|
||||||
Assume `_shared_requests.md` contains:
|
Assume `_shared_requests.md` contains:
|
||||||
|
|
||||||
````markdown
|
::raw-md[./examples/_shared_requests.md]
|
||||||
```http id=sharedGetRequest
|
|
||||||
GET https://httpbin.org/get
|
|
||||||
```
|
|
||||||
````
|
|
||||||
|
|
||||||
Then, in `main.md`:
|
Then, in `main.md`:
|
||||||
|
|
||||||
````markdown
|
::raw-md[./examples/with-shared-requests.md]
|
||||||
# Main Document
|
|
||||||
|
|
||||||
Let's include some shared requests:
|
<details>
|
||||||
|
<summary>Output</summary>
|
||||||
|
|
||||||
::md[./_shared_requests.md]
|
::raw-md[./examples/with-shared-requests.md]{render}
|
||||||
|
|
||||||
The shared GET request returned: {{responses.sharedGetRequest.status}}
|
</details>
|
||||||
|
|
||||||
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.
|
||||||
|
|
||||||
|
|||||||
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: {{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
|
||||||
@@ -10,6 +10,7 @@ type Response = {
|
|||||||
statusText: string;
|
statusText: string;
|
||||||
headers: Record<string, string>;
|
headers: Record<string, string>;
|
||||||
body?: string;
|
body?: string;
|
||||||
|
rawBody?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
type AddRequestOptios = {
|
type AddRequestOptios = {
|
||||||
|
|||||||
@@ -59,7 +59,8 @@ const httpHandler: ExecutionHandler = ({
|
|||||||
body
|
body
|
||||||
});
|
});
|
||||||
|
|
||||||
let responseText = await response.text();
|
const rawBody = await response.text();
|
||||||
|
let responseText = rawBody;
|
||||||
if (options.json) {
|
if (options.json) {
|
||||||
try {
|
try {
|
||||||
responseText = JSON.parse(responseText);
|
responseText = JSON.parse(responseText);
|
||||||
@@ -84,6 +85,7 @@ 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,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user