Improve the documentation and bug fixes #3

Merged
dorian merged 13 commits from improve-docs into main 2024-02-24 20:41:15 -05:00
3 changed files with 36 additions and 32 deletions
Showing only changes of commit 780ab23310 - Show all commits

View File

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

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
/// * `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,