From 6b74a28989ed105bbe2e6308890467a6f05ee0bf Mon Sep 17 00:00:00 2001 From: Morten Olsen Date: Sun, 18 May 2025 21:18:05 +0200 Subject: [PATCH] docs: improved docs --- docs/README.md | 28 ++++++------------------- docs/examples/_shared_requests.md | 3 +++ docs/examples/with-shared-requests.md | 18 ++++++++++++++++ src/context/context.ts | 1 + src/execution/handlers/handlers.http.ts | 4 +++- 5 files changed, 31 insertions(+), 23 deletions(-) create mode 100644 docs/examples/_shared_requests.md create mode 100644 docs/examples/with-shared-requests.md diff --git a/docs/README.md b/docs/README.md index 62190d9..738be72 100644 --- a/docs/README.md +++ b/docs/README.md @@ -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-shared-requests.md] -Let's include some shared requests: +
+ Output -::md[./_shared_requests.md] +::raw-md[./examples/with-shared-requests.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 -```` +
When `main.md` is processed, `_shared_requests.md` will be embedded, its `sharedGetRequest` will be executed, and its data will be available for templating. diff --git a/docs/examples/_shared_requests.md b/docs/examples/_shared_requests.md new file mode 100644 index 0000000..e806fd3 --- /dev/null +++ b/docs/examples/_shared_requests.md @@ -0,0 +1,3 @@ +```http #sharedGetRequest +GET https://httpbin.org/get +``` diff --git a/docs/examples/with-shared-requests.md b/docs/examples/with-shared-requests.md new file mode 100644 index 0000000..488f96b --- /dev/null +++ b/docs/examples/with-shared-requests.md @@ -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 diff --git a/src/context/context.ts b/src/context/context.ts index 81c60f4..d7ccdec 100644 --- a/src/context/context.ts +++ b/src/context/context.ts @@ -10,6 +10,7 @@ type Response = { statusText: string; headers: Record; body?: string; + rawBody?: string; }; type AddRequestOptios = { diff --git a/src/execution/handlers/handlers.http.ts b/src/execution/handlers/handlers.http.ts index 3c371b7..ba41861 100644 --- a/src/execution/handlers/handlers.http.ts +++ b/src/execution/handlers/handlers.http.ts @@ -59,7 +59,8 @@ const httpHandler: ExecutionHandler = ({ body }); - let responseText = await response.text(); + const rawBody = await response.text(); + let responseText = rawBody; if (options.json) { try { responseText = JSON.parse(responseText); @@ -84,6 +85,7 @@ const httpHandler: ExecutionHandler = ({ statusText: response.statusText, headers: Object.fromEntries(response.headers.entries()), body: responseText, + rawBody: rawBody, }, }); },