Finish documenting the codebase.
continuous-integration/drone/push Build is failing Details

This commit is contained in:
Dorian 2024-02-24 12:34:19 -05:00
parent f14963a2c4
commit 780ab23310
3 changed files with 36 additions and 32 deletions

View File

@ -46,6 +46,9 @@ Afterward you can run using `mirror-server`
## Usage ## Usage
You can get all the options that `mirror-server` supports by running it with
the help option `--help` or `-h`:
```console ```console
$ mirror-server --help $ mirror-server --help
A simple server for mirror HTTP requests for testing. A simple server for mirror HTTP requests for testing.
@ -58,3 +61,31 @@ Options:
-h, --help Print help -h, --help Print help
-V, --version Print version -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"
}
}
```

View File

@ -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"
}
}

View File

@ -51,24 +51,12 @@ struct EchoResponse {
/// ///
/// ## Arguments /// ## Arguments
/// * `method` - The HTTP [`Method`] used for the request. i.e. `GET`, `POST`, `PATCH`, etc. /// * `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( async fn echo_request(
method: Method, method: Method,
original_uri: OriginalUri, original_uri: OriginalUri,