From f14963a2c4d125dd3c019eec126deb3d8e2461bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dorian=20Pu=C5=82a?= Date: Sat, 24 Feb 2024 10:04:22 -0500 Subject: [PATCH] Add a sample curl and JSON response to the API. --- examples/sample-response.json | 15 +++++++++++++++ src/main.rs | 19 +++++++++++++++++-- 2 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 examples/sample-response.json diff --git a/examples/sample-response.json b/examples/sample-response.json new file mode 100644 index 0000000..a110a95 --- /dev/null +++ b/examples/sample-response.json @@ -0,0 +1,15 @@ +{ + "method": "PUT", + "path": "/api/testing", + "host": "localhost:8180", + "headers": { + "accept": "*/*", + "content-length": "18", + "content-type": "application/json", + "host": "localhost:8180", + "user-agent": "curl/7.68.0" + }, + "body": { + "hello": "world" + } +} diff --git a/src/main.rs b/src/main.rs index 180f10a..3c3a882 100644 --- a/src/main.rs +++ b/src/main.rs @@ -49,11 +49,26 @@ struct EchoResponse { /// /// Captures the request and responds with a JSON response of the elements of the request. /// -/// TODO: Add a example of the JSON output of the response. -/// /// ## Arguments /// * `method` - The HTTP [`Method`] used for the request. i.e. `GET`, `POST`, `PATCH`, etc. /// TODO: Document the rest of the arguments +/// +/// ## Example +/// +/// Sending a request using `curl`: +/// +/// ```console +/// $ curl -s -X PUT -D '{"hello": "world"}' -H 'Content-Type: application/json' \ +/// http://localhost:8080/api/testing | jq . +/// ``` +/// +/// Results in a JSON response: +/// +/// ```json +#[doc = include_str!("../examples/sample-response.json")] +/// ``` +/// + async fn echo_request( method: Method, original_uri: OriginalUri,