David Pedersen
80a8355eff
Remove generic parameter from BodyStream ( #234 )
...
I think `BodyStream` is more useful without being generic over the
request body.
I'm also looking into adding a response body from a stream called
`StreamBody` which will work pretty much opposite to this.
2021-08-22 11:33:38 +02:00
David Pedersen
add3dc36f9
Rename extract::Body to extract::RawBody ( #233 )
2021-08-21 20:04:39 +02:00
David Pedersen
ca4d9a2bb9
Replace route with Router::new().route() ( #215 )
...
This way there is now only one way to create a router:
```rust
use axum::{Router, handler::get};
let app = Router::new()
.route("/foo", get(handler))
.route("/foo", get(handler));
```
`nest` was changed in the same way:
```rust
use axum::Router;
let app = Router::new().nest("/foo", service);
```
2021-08-19 22:37:48 +02:00
David Pedersen
97b53768ba
Replace RoutingDsl trait with Router type ( #214 )
...
* Remove `RoutingDsl`
* Fix typo
2021-08-19 21:24:32 +02:00
David Pedersen
e22045d42f
Change nested routes to see the URI with prefix stripped ( #197 )
2021-08-18 09:48:36 +02:00
Florian Thelliez
d9a06ef14b
Remove axum::prelude ( #195 )
2021-08-18 00:04:15 +02:00
David Pedersen
baa99e5084
Make RequestParts::{new, try_into_request} public ( #194 )
...
Fixes https://github.com/tokio-rs/axum/issues/147
2021-08-16 20:55:22 +02:00
David Pedersen
6b218c7150
Clean up RequestParts API ( #167 )
...
In http-body 0.4.3 `BoxBody` implements `Default`. This allows us to
clean up the API of `RequestParts` quite a bit.
2021-08-08 19:48:30 +02:00
David Pedersen
bc27b09f5c
Make sure nested services still see full URI ( #166 )
...
They'd previously see the nested URI as we mutated the request. Now we
always route based on the nested URI (if present) without mutating the
request. Also meant we could get rid of `OriginalUri` which is nice.
2021-08-08 17:27:23 +02:00
David Pedersen
b4bdddf9d2
Add NestedUri ( #161 )
...
Fixes https://github.com/tokio-rs/axum/issues/159
2021-08-08 14:45:31 +02:00
David Pedersen
c570fb2d52
Fix Uri extractor not being the full URI if using nest ( #156 )
2021-08-07 22:07:50 +02:00
David Pedersen
a6b3e09827
Remove UrlParamsMap and UrlParams ( #154 )
...
Use `extract::Path` instead.
2021-08-07 21:22:08 +02:00
David Pedersen
4bb17cbc2d
Remove take_* methods from RequestParts for Version, Method, and Uri ( #151 )
...
* Remove `RequestParts::take_method`
* Remove `RequestParts::take_uri`
* Remove `RequestParts::take_version`
2021-08-07 20:24:13 +02:00
David Pedersen
4194cf70da
Change WebSocket API to use an extractor ( #121 )
...
Fixes https://github.com/tokio-rs/axum/issues/111
Example usage:
```rust
use axum::{
prelude::*,
extract::ws::{WebSocketUpgrade, WebSocket},
response::IntoResponse,
};
let app = route("/ws", get(handler));
async fn handler(ws: WebSocketUpgrade) -> impl IntoResponse {
ws.on_upgrade(handle_socket)
}
async fn handle_socket(mut socket: WebSocket) {
while let Some(msg) = socket.recv().await {
let msg = if let Ok(msg) = msg {
msg
} else {
// client disconnected
return;
};
if socket.send(msg).await.is_err() {
// client disconnected
return;
}
}
}
```
2021-08-07 17:26:23 +02:00
David Pedersen
404a3b5e8a
Add default for RequestParts type param ( #148 )
...
Same reason as https://github.com/tokio-rs/axum/pull/146
2021-08-07 17:10:00 +02:00
Sunli
345163e98d
Common JSON wrapper type for response and request ( #140 )
2021-08-07 16:07:13 +02:00
David Pedersen
3d45a97db9
Make FromRequest default to use axum::body::Body ( #146 )
...
Most users will implement `FromRequest<axum::body::Body>` so making that
the default makes things a bit easier to use.
2021-08-07 12:22:14 +02:00
David Pedersen
811b1d896c
Deprecate extract::UrlParams and extract::UrlParamsMap ( #138 )
...
Use `extract::Path` instead. It supports everything the two other do,
and more.
2021-08-06 10:38:38 +02:00
Sunli
9fdbd42fba
Implement path extractor ( #124 )
...
Fixes #42
2021-08-06 10:17:57 +02:00
David Pedersen
5c12328892
Replace hyper::Server with axum::Server in docs ( #118 )
...
* Replace `hyper::Server` with `axum::Server` in docs
* Change readme as well
2021-08-04 15:38:51 +02:00
David Pedersen
9a6bc4e962
Break up extract.rs ( #103 )
...
This breaks up `extract.rs` into several smaller submodules. The public
API remains the same.
This is done in prep for adding more tests to extractors which would get
messy if they were all in the same file.
2021-08-03 21:55:48 +02:00
David Pedersen
2cf28c6794
Improve error message of MissingExtension rejections ( #72 )
...
Now includes the name of missing type.
2021-08-01 15:50:57 +02:00
David Pedersen
f67abd1ee2
Add extractor for remote connection info ( #55 )
...
Fixes https://github.com/tokio-rs/axum/issues/43
With this you can get the remote address like so:
```rust
use axum::{prelude::*, extract::ConnectInfo};
use std::net::SocketAddr;
let app = route("/", get(handler));
async fn handler(ConnectInfo(addr): ConnectInfo<SocketAddr>) -> String {
format!("Hello {}", addr)
}
// Starting the app with `into_make_service_with_connect_info` is required
// for `ConnectInfo` to work.
let make_svc = app.into_make_service_with_connect_info::<SocketAddr, _>();
hyper::Server::bind(&"0.0.0.0:3000".parse().unwrap())
.serve(make_svc)
.await
.expect("server failed");
```
This API is fully generic and supports whatever transport layer you're using with Hyper. I've updated the unix domain socket example to extract `peer_creds` and `peer_addr`.
2021-07-31 21:36:30 +02:00
David Pedersen
5407247e90
Implement Deref for extractors ( #56 )
...
Fixes https://github.com/tokio-rs/axum/issues/54
2021-07-31 14:54:10 +02:00
David Pedersen
d843f4378b
Make websocket handlers support extractors ( #41 )
2021-07-30 15:19:53 +02:00
David Pedersen
d927c819d3
Clarify docs around body extractors
2021-07-23 00:27:08 +02:00
David Pedersen
8faed8120f
Docs improvements ( #37 )
2021-07-22 15:00:33 +02:00
David Pedersen
f32d325e55
Make extractors easier to write ( #36 )
...
Previously extractors worked directly on `Request<B>` which meant you
had to do weird tricks like `mem::take(req.headers_mut())` to get owned
parts of the request.
This changes that instead to use a new `RequestParts` type that have
methods to "take" each part of the request. Without having to do weird
tricks.
Also removed the need to have `B: Default` for body extractors.
2021-07-22 13:23:50 +02:00
David Pedersen
028c472c84
Add Multipart extractor for consuming multipart/form-data requests ( #32 )
...
Multipart implementation on top of `multer`
2021-07-14 16:53:37 +02:00
David Pedersen
341ad61240
Clarify body extractors
2021-07-10 23:46:14 +02:00
David Pedersen
1cbd43cfc4
Add extractor_middleware ( #29 )
...
Converts an extractor into a middleware so it can be run for many routes
without having to repeat it in the function signature.
2021-07-09 23:38:59 +02:00
David Pedersen
5a5710d290
Rename to axum ( #28 )
2021-07-09 21:36:14 +02:00
David Pedersen
356f1c8424
Generic request body ( #22 )
...
Fixes #21
2021-06-19 12:50:33 +02:00
David Pedersen
b6e67eefd7
Add support for extracting typed headers ( #18 )
...
Uses the `headers` crate.
2021-06-15 21:27:21 +02:00
David Pedersen
c41c9e0f78
Support extracting URL params multiple times ( #15 )
...
Useful when building higher order extractors.
2021-06-13 13:06:33 +02:00
David Pedersen
2b360a7873
Support getting error from extractors ( #14 )
...
Makes `Result<T, T::Rejection>` an extractor and makes all extraction errors enums so no type information is lost.
2021-06-13 12:06:59 +02:00
David Pedersen
1002685a20
Rename to awebframework ( #13 )
2021-06-13 11:22:02 +02:00
David Pedersen
27ebb3db7a
Add Form extractor ( #12 )
...
Fixes https://github.com/davidpdrsn/tower-web/issues/2
2021-06-13 11:01:40 +02:00
David Pedersen
b3bc4e024c
Add RoutingDsl::{serve, into_make_service} ( #8 )
2021-06-12 21:44:40 +02:00
David Pedersen
002e3f92b3
Misc repo setup ( #7 )
2021-06-12 20:18:21 +02:00
David Pedersen
c91dc7ce29
Make Request<Body> an extractor
2021-06-09 09:42:06 +02:00
David Pedersen
90c3e5ba74
Parameterize ContentLengthLimit
2021-06-09 08:14:20 +02:00
David Pedersen
09f76f3c87
More notes on backpressure
2021-06-09 07:52:04 +02:00
David Pedersen
1cf78fa807
More docs
2021-06-08 22:04:28 +02:00
David Pedersen
1f8b39f05d
More docs and expand key_value_store example
2021-06-08 12:43:16 +02:00
David Pedersen
d376e49eb9
More docs
2021-06-07 16:28:40 +02:00
David Pedersen
7620f17edc
Remove some needless type params
2021-06-06 22:41:52 +02:00
David Pedersen
a005427d40
Write some docs
2021-06-06 15:19:54 +02:00
David Pedersen
46398afc72
Move things around a bit
2021-06-06 11:37:08 +02:00