Improve the documentation of the crate.
continuous-integration/drone/push Build is failing
Details
continuous-integration/drone/push Build is failing
Details
This commit is contained in:
parent
aca5a57460
commit
762186ea2f
10
README.md
10
README.md
|
@ -14,7 +14,7 @@ working with REST API JSON calls, and catching headers.
|
||||||
* Create a DEB package:
|
* Create a DEB package:
|
||||||
* Install cargo-deb: `cargo install cargo-deb`
|
* Install cargo-deb: `cargo install cargo-deb`
|
||||||
* Create the DEB package: `cargo deb`
|
* Create the DEB package: `cargo deb`
|
||||||
* Faster builds using [cargo-watch](https://watchexec.github.io/#cargo-watch): `cargo watch -x run`
|
* Faster builds using [`cargo-watch`](https://watchexec.github.io/#cargo-watch): `cargo watch -x run`
|
||||||
* Installing the binary locally from source: `cargo install --path .`
|
* Installing the binary locally from source: `cargo install --path .`
|
||||||
|
|
||||||
## Install
|
## Install
|
||||||
|
@ -27,8 +27,8 @@ the latest (or tagged) release.
|
||||||
|
|
||||||
Run via Docker using:
|
Run via Docker using:
|
||||||
|
|
||||||
```bash
|
```console
|
||||||
docker run -p 8080:8080 code.birch-tree.net/dorian/mirror-server:latest
|
$ docker run -p 8080:8080 code.birch-tree.net/dorian/mirror-server:latest
|
||||||
```
|
```
|
||||||
|
|
||||||
### Debian Package
|
### Debian Package
|
||||||
|
@ -46,8 +46,8 @@ Afterward you can run using `mirror-server`
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
```bash
|
```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.
|
||||||
|
|
||||||
Usage: mirror-server [OPTIONS]
|
Usage: mirror-server [OPTIONS]
|
||||||
|
|
18
src/main.rs
18
src/main.rs
|
@ -13,7 +13,7 @@ use tower_http::trace;
|
||||||
use tracing::{info, warn, Level};
|
use tracing::{info, warn, Level};
|
||||||
|
|
||||||
|
|
||||||
/// CLI arguments used by the [Parser].
|
/// CLI arguments used by the [`Parser`].
|
||||||
///
|
///
|
||||||
/// Creates the usage and version information that is standard in a CLI
|
/// Creates the usage and version information that is standard in a CLI
|
||||||
/// utility.
|
/// utility.
|
||||||
|
@ -32,7 +32,7 @@ struct CliArgs {
|
||||||
/// The response consisting of the echoed request to the mirror-server.
|
/// The response consisting of the echoed request to the mirror-server.
|
||||||
#[derive(Serialize, Deserialize, Debug, PartialEq)]
|
#[derive(Serialize, Deserialize, Debug, PartialEq)]
|
||||||
struct EchoResponse {
|
struct EchoResponse {
|
||||||
/// The [Method] used in the request.
|
/// The [`Method`] used in the request.
|
||||||
method: String,
|
method: String,
|
||||||
/// The path used in the request.
|
/// The path used in the request.
|
||||||
path: String,
|
path: String,
|
||||||
|
@ -45,6 +45,15 @@ struct EchoResponse {
|
||||||
body: Option<Value>,
|
body: Option<Value>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// [`Handler`](axum::handler) for responding with a break-down of the captured request.
|
||||||
|
///
|
||||||
|
/// 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
|
||||||
async fn echo_request(
|
async fn echo_request(
|
||||||
method: Method,
|
method: Method,
|
||||||
original_uri: OriginalUri,
|
original_uri: OriginalUri,
|
||||||
|
@ -80,6 +89,10 @@ async fn echo_request(
|
||||||
Json(response)
|
Json(response)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Create a [`Router`] to handling capture all HTTP requests to the server.
|
||||||
|
///
|
||||||
|
/// Wires up a default catch-all route for the application. Also adds the tracing infrastructure
|
||||||
|
/// to capture requests.
|
||||||
fn app() -> Router {
|
fn app() -> Router {
|
||||||
Router::new().fallback(echo_request).layer(
|
Router::new().fallback(echo_request).layer(
|
||||||
trace::TraceLayer::new_for_http()
|
trace::TraceLayer::new_for_http()
|
||||||
|
@ -88,6 +101,7 @@ fn app() -> Router {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The main application starts the mirror-server application.
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() {
|
async fn main() {
|
||||||
let cli_args = CliArgs::parse();
|
let cli_args = CliArgs::parse();
|
||||||
|
|
Loading…
Reference in New Issue