.. | ||
dir | ||
tls | ||
autoreload.rs | ||
body.rs | ||
compression.rs | ||
custom_methods.rs | ||
dir.rs | ||
dyn_reply.rs | ||
file.rs | ||
futures.rs | ||
handlebars_template.rs | ||
headers.rs | ||
hello.rs | ||
multipart.rs | ||
query_string.rs | ||
README.md | ||
rejections.rs | ||
returning.rs | ||
routing.rs | ||
sse_chat.rs | ||
sse.rs | ||
stream.rs | ||
tls.rs | ||
todos.rs | ||
tracing.rs | ||
unix_socket.rs | ||
websockets_chat.rs | ||
websockets.rs | ||
wrapping.rs |
Examples
Welcome to the examples! These show off warp
's functionality and explain how to use it.
Getting Started
To get started, run examples/hello.rs
with:
> cargo run --example hello
This will start a simple "hello world" service running on your localhost port 3030.
Open another terminal and run:
> curl http://localhost:3030/hi
Hello, World!%
Congratulations, you have just run your first warp service!
You can run other examples with cargo run --example [example name]
:
hello.rs
- Just a basic "Hello World" APIrouting.rs
- Builds up a more complex set of routes and shows how to combine filtersbody.rs
- What's a good API without parsing data from the request body?headers.rs
- Parsing data from the request headersrejections.rs
- Your APIs are obviously perfect, but for silly others who call them incorrectly you'll want to define errors for themfutures.rs
- Wait, wait! ... Or how to integrate futures into filterstodos.rs
- Putting this all together with a proper app
Further Use Cases
Serving HTML and Other Files
file.rs
- Serving static filesdir.rs
- Or a whole directory of fileshandlebars_template.rs
- Using Handlebars to fill in an HTML template
Websockets
Hooray! warp
also includes built-in support for WebSockets
websockets.rs
- Basic handling of a WebSocket upgradewebsockets_chat.rs
- Full WebSocket app
Server-Side Events
sse.rs
- Basic Server-Side Eventsse_chat.rs
- Full SSE app
TLS
tls.rs
- can i haz security?
Autoreloading
autoreload.rs
- Change some code and watch the server reload automatically!
Debugging
tracing.rs
- Warp has built-in support for rich diagnostics withtracing
!
Custom HTTP Methods
custom_methods.rs
- It is also possible to use Warp with custom HTTP methods.