Skip to content

Commit

Permalink
Add details about starting a stand-alone server
Browse files Browse the repository at this point in the history
  • Loading branch information
lipanski committed Feb 21, 2024
1 parent a09f1f0 commit a982823
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
17 changes: 17 additions & 0 deletions README.md
Expand Up @@ -120,6 +120,23 @@ async fn test_simple_route_mock_async() {
}
```

Start a **stand-alone server** on a dedicated port:

```rust
fn main() {
let opts = mockito::ServerOpts {
host: "0.0.0.0",
port: 1234,
..Default::default()
};
let mut server = mockito::Server::new_with_opts(opts);

let _m = server.mock("GET", "/").with_body("hello world").create();

loop {}
}
```

## Minimum supported Rust toolchain

The current minimum support Rust toolchain is **1.68.0**
Expand Down
11 changes: 7 additions & 4 deletions examples/mockito-server.rs
@@ -1,11 +1,14 @@
use mockito;

use std::time::Duration;

fn main() {
let mut s = mockito::Server::new();
let opts = mockito::ServerOpts {
host: "0.0.0.0",
port: 1234,
..Default::default()
};
let mut server = mockito::Server::new_with_opts(opts);

s.mock("GET", "/").with_body("hello world");
let _m = server.mock("GET", "/").with_body("hello world").create();

loop {
std::thread::sleep(Duration::from_secs(1))
Expand Down

0 comments on commit a982823

Please sign in to comment.