From 780ab23310d8421c771b66787998e07186de4b15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dorian=20Pu=C5=82a?= Date: Sat, 24 Feb 2024 12:34:19 -0500 Subject: [PATCH] Finish documenting the codebase. --- README.md | 31 +++++++++++++++++++++++++++++++ examples/sample-response.json | 15 --------------- src/main.rs | 22 +++++----------------- 3 files changed, 36 insertions(+), 32 deletions(-) delete mode 100644 examples/sample-response.json diff --git a/README.md b/README.md index 002fd76..a44b0a8 100644 --- a/README.md +++ b/README.md @@ -46,6 +46,9 @@ Afterward you can run using `mirror-server` ## Usage +You can get all the options that `mirror-server` supports by running it with +the help option `--help` or `-h`: + ```console $ mirror-server --help A simple server for mirror HTTP requests for testing. @@ -58,3 +61,31 @@ Options: -h, --help Print help -V, --version Print version ``` + +After starting the server, you can send requests to it. Using `curl` you +can send `mirror-server` JSON requests: + +```console +$ curl -s -X PUT -D '{"hello": "world"}' -H 'Content-Type: application/json' \ + http://localhost:8080/api/testing | jq . +``` + +And `mirror-server` responds to requests with JSON responses: + +```json +{ + "method": "PUT", + "path": "/api/testing", + "host": "localhost:8180", + "headers": { + "accept": "*/*", + "content-length": "18", + "content-type": "application/json", + "host": "localhost:8080", + "user-agent": "curl/7.68.0" + }, + "body": { + "hello": "world" + } +} +``` diff --git a/examples/sample-response.json b/examples/sample-response.json deleted file mode 100644 index a110a95..0000000 --- a/examples/sample-response.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "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 3c3a882..13a8c5e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -51,24 +51,12 @@ struct EchoResponse { /// /// ## Arguments /// * `method` - The HTTP [`Method`] used for the request. i.e. `GET`, `POST`, `PATCH`, etc. -/// TODO: Document the rest of the arguments +/// * `original_uri` - The URI used for the request. +/// * `host` - The hostname of the request. +/// * `header_map` - A map with the headers used during the request. +/// * `body` - An optional JSON body, if it is past in to the request. +/// Requires a header of `Content-Type: application/json` and a body passed in the request. /// -/// ## 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,