| 1 |
# Examples |
| 2 |
|
| 3 |
Welcome to the examples! These show off `warp`'s functionality and explain how to use it. |
| 4 |
|
| 5 |
## Getting Started |
| 6 |
|
| 7 |
To get started, run `examples/hello.rs` with: |
| 8 |
|
| 9 |
```bash |
| 10 |
> cargo run --example hello |
| 11 |
``` |
| 12 |
|
| 13 |
This will start a simple "hello world" service running on your localhost port 3030. |
| 14 |
|
| 15 |
Open another terminal and run: |
| 16 |
|
| 17 |
```bash |
| 18 |
> curl http://localhost:3030/hi |
| 19 |
Hello, World!% |
| 20 |
``` |
| 21 |
|
| 22 |
Congratulations, you have just run your first warp service! |
| 23 |
|
| 24 |
You can run other examples with `cargo run --example [example name]`: |
| 25 |
|
| 26 |
- [`hello.rs`](./hello.rs) - Just a basic "Hello World" API |
| 27 |
- [`routing.rs`](./routing.rs) - Builds up a more complex set of routes and shows how to combine filters |
| 28 |
- [`body.rs`](./body.rs) - What's a good API without parsing data from the request body? |
| 29 |
- [`headers.rs`](./headers.rs) - Parsing data from the request headers |
| 30 |
- [`rejections.rs`](./rejections.rs) - Your APIs are obviously perfect, but for silly others who call them incorrectly you'll want to define errors for them |
| 31 |
- [`futures.rs`](./futures.rs) - Wait, wait! ... Or how to integrate futures into filters |
| 32 |
- [`todos.rs`](./todos.rs) - Putting this all together with a proper app |
| 33 |
|
| 34 |
## Further Use Cases |
| 35 |
|
| 36 |
### Serving HTML and Other Files |
| 37 |
|
| 38 |
- [`file.rs`](./file.rs) - Serving static files |
| 39 |
- [`dir.rs`](./dir.rs) - Or a whole directory of files |
| 40 |
- [`handlebars_template.rs`](./handlebars_template.rs) - Using Handlebars to fill in an HTML template |
| 41 |
|
| 42 |
### Websockets |
| 43 |
|
| 44 |
Hooray! `warp` also includes built-in support for WebSockets |
| 45 |
|
| 46 |
- [`websockets.rs`](./websockets.rs) - Basic handling of a WebSocket upgrade |
| 47 |
- [`websockets_chat.rs`](./websockets_chat.rs) - Full WebSocket app |
| 48 |
|
| 49 |
### Server-Side Events |
| 50 |
|
| 51 |
- [`sse.rs`](./sse.rs) - Basic Server-Side Event |
| 52 |
- [`sse_chat.rs`](./sse_chat.rs) - Full SSE app |
| 53 |
|
| 54 |
### TLS |
| 55 |
|
| 56 |
- [`tls.rs`](./tls.rs) - can i haz security? |
| 57 |
|
| 58 |
### Autoreloading |
| 59 |
|
| 60 |
- [`autoreload.rs`](./autoreload.rs) - Change some code and watch the server reload automatically! |
| 61 |
|
| 62 |
### Debugging |
| 63 |
|
| 64 |
- [`tracing.rs`](./tracing.rs) - Warp has built-in support for rich diagnostics with [`tracing`](https://docs.rs/tracing)! |
| 65 |
|
| 66 |
## Custom HTTP Methods |
| 67 |
|
| 68 |
- [`custom_methods.rs`](./custom_methods.rs) - It is also possible to use Warp with custom HTTP methods. |