Improve the documentation and bug fixes #3
31
README.md
31
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"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
|
|
@ -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"
|
||||
}
|
||||
}
|
22
src/main.rs
22
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,
|
||||
|
|
Loading…
Reference in New Issue