From c6cad623200d7bb13bab18aea3cf2fe3b9e7dfb7 Mon Sep 17 00:00:00 2001 From: reigj1 Date: Tue, 3 Sep 2024 11:40:35 +0200 Subject: [PATCH] fix issue #3417 --- .../serving-http-request.mdx | 27 ++++++++++++++----- 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/docs/developer-docs/smart-contracts/advanced-features/serving-http-request.mdx b/docs/developer-docs/smart-contracts/advanced-features/serving-http-request.mdx index e3b4c82bfb..bd3e9573c5 100644 --- a/docs/developer-docs/smart-contracts/advanced-features/serving-http-request.mdx +++ b/docs/developer-docs/smart-contracts/advanced-features/serving-http-request.mdx @@ -14,19 +14,27 @@ import { MarkdownChipRow } from "/src/components/Chip/MarkdownChipRow"; ## Overview -Canisters can serve or handle an incoming HTTP request using the [HTTP Gateway Protocol](/docs/current/references/http-gateway-protocol-spec). +Canisters can serve or handle an incoming HTTP request using the +[HTTP Gateway Protocol](/docs/current/references/http-gateway-protocol-spec). This allows developers to host web applications and APIs from a canister. ## How it works -An HTTP request from a client gets intercepted by the HTTP Gateway Protocol, which identifies the target canister and encodes the request in Candid. This encoded request is then sent to the canister for processing. Once processed, the canister replies with an HTTP response. Finally, the HTTP Gateway Protocol decodes the response using Candid and sends it back to the client, completing the communication loop. +An HTTP request from a client gets intercepted by the HTTP Gateway Protocol, +which identifies the target canister and encodes the request in Candid. This +encoded request is then sent to the canister for processing. Once processed, the +canister replies with an HTTP response. Finally, the HTTP Gateway Protocol +decodes the response using Candid and sends it back to the client, completing +the communication loop. -For detailed information on how it works, please refer to the [HTTP Gateway Protocol specification](/docs/current/references/http-gateway-protocol-spec). +For detailed information on how it works, please refer to the +[HTTP Gateway Protocol specification](/docs/current/references/http-gateway-protocol-spec). ## How to make a request -The following example returns 'Hello, World!' in the body at the `/hello` endpoint. +The following example returns 'Hello, World!' in the body at the `/hello` +endpoint. @@ -222,11 +230,18 @@ def http_request(req: HttpRequest) -> HttpResponse: "body": b"404 Not found :", } ``` -To learn more about serving an HTTP request in Python, refer to [the Kybra book reference on incoming HTTP requests](https://demergent-labs.github.io/kybra/http.html). + +To learn more about serving an HTTP request in Python, refer to +[the Kybra book reference on incoming HTTP requests](https://demergent-labs.github.io/kybra/http.html). ## Additional examples -The [HTTP counter project](../../../references/samples/motoko/http_counter) is an example in Motoko of a 'counter' application that uses the `http_request` method to read the current counter value or access some pre-stored data and the `http_request_update` method to increment the counter and retrieve the updated value. +The +[HTTP counter project](https://github.com/dfinity/examples/tree/master/motoko/http_counter) +is an example in Motoko of a 'counter' application that uses the `http_request` +method to read the current counter value or access some pre-stored data and the +`http_request_update` method to increment the counter and retrieve the updated +value.