Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace RoutingDsl trait with Router type #214

Merged
merged 2 commits into from
Aug 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Overall compile time improvements. If you're having issues with compile time
please file an issue!
- Remove `prelude`. Explicit imports are now required.
- Add dedicated `Router` to replace the `RoutingDsl` trait
- Make `FromRequest` default to being generic over `body::Body` ([#146](https://github.com/tokio-rs/axum/pull/146))
- Implement `std::error::Error` for all rejections ([#153](https://github.com/tokio-rs/axum/pull/153))
- Add `RoutingDsl::or` for combining routes ([#108](https://github.com/tokio-rs/axum/pull/108))
- Add `Router::or` for combining routes ([#108](https://github.com/tokio-rs/axum/pull/108))
- Add `handle_error` to `service::OnMethod` ([#160](https://github.com/tokio-rs/axum/pull/160))
- Add `OriginalUri` for extracting original request URI in nested services ([#197](https://github.com/tokio-rs/axum/pull/197))
- Implement `FromRequest` for `http::Extensions`
Expand All @@ -32,16 +33,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Change WebSocket API to use an extractor ([#121](https://github.com/tokio-rs/axum/pull/121))
- Make WebSocket `Message` an enum ([#116](https://github.com/tokio-rs/axum/pull/116))
- `WebSocket` now uses `Error` as its error type ([#150](https://github.com/tokio-rs/axum/pull/150))
- Ensure a `HandleError` service created from `ServiceExt::handle_error`
_does not_ implement `RoutingDsl` as that could lead to confusing routing
behavior ([#120](https://github.com/tokio-rs/axum/pull/120))
- Implement `routing::MethodFilter` via [`bitflags`](https://crates.io/crates/bitflags)
- Removed `extract::UrlParams` and `extract::UrlParamsMap`. Use `extract::Path` instead
- `EmptyRouter` now requires the response body to implement `Send + Sync + 'static'` ([#108](https://github.com/tokio-rs/axum/pull/108))
- `ServiceExt` has been removed and its methods have been moved to `RoutingDsl` ([#160](https://github.com/tokio-rs/axum/pull/160))
- `extractor_middleware` now requires `RequestBody: Default` ([#167](https://github.com/tokio-rs/axum/pull/167))
- Convert `RequestAlreadyExtracted` to an enum with each possible error variant ([#167](https://github.com/tokio-rs/axum/pull/167))
- `RoutingDsl::check_infallible` now returns a `CheckInfallible` service. This
- `Router::check_infallible` now returns a `CheckInfallible` service. This
is to improve compile times.
- These future types have been moved
- `extract::extractor_middleware::ExtractorMiddlewareResponseFuture` moved
Expand Down
5 changes: 1 addition & 4 deletions examples/async-graphql/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@ mod starwars;
use async_graphql::http::{playground_source, GraphQLPlaygroundConfig};
use async_graphql::{EmptyMutation, EmptySubscription, Request, Response, Schema};
use axum::response::IntoResponse;
use axum::{
extract::Extension, handler::get, response::Html, route, routing::RoutingDsl,
AddExtensionLayer, Json,
};
use axum::{extract::Extension, handler::get, response::Html, route, AddExtensionLayer, Json};
use starwars::{QueryRoot, StarWars, StarWarsSchema};

async fn graphql_handler(schema: Extension<StarWarsSchema>, req: Json<Request>) -> Json<Response> {
Expand Down
1 change: 0 additions & 1 deletion examples/chat/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use axum::extract::Extension;
use axum::handler::get;
use axum::response::{Html, IntoResponse};
use axum::route;
use axum::routing::RoutingDsl;
use axum::AddExtensionLayer;
use futures::{sink::SinkExt, stream::StreamExt};
use std::collections::HashSet;
Expand Down
4 changes: 1 addition & 3 deletions examples/error-handling-and-dependency-injection/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ use axum::{
handler::{get, post},
http::{Response, StatusCode},
response::IntoResponse,
route,
routing::RoutingDsl,
AddExtensionLayer, Json,
route, AddExtensionLayer, Json,
};
use serde::{Deserialize, Serialize};
use serde_json::json;
Expand Down
2 changes: 1 addition & 1 deletion examples/form/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//! cargo run -p example-form
//! ```

use axum::{extract::Form, handler::get, response::Html, route, routing::RoutingDsl};
use axum::{extract::Form, handler::get, response::Html, route};
use serde::Deserialize;
use std::net::SocketAddr;

Expand Down
1 change: 0 additions & 1 deletion examples/global-404-handler/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use axum::{
http::{Response, StatusCode},
response::Html,
route,
routing::RoutingDsl,
};
use std::net::SocketAddr;
use tower::util::MapResponseLayer;
Expand Down
2 changes: 1 addition & 1 deletion examples/hello-world/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//! cargo run -p example-hello-world
//! ```

use axum::{handler::get, route, routing::RoutingDsl};
use axum::{handler::get, route};
use std::net::SocketAddr;

#[tokio::main]
Expand Down
6 changes: 3 additions & 3 deletions examples/key-value-store/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
//! ```

use axum::{
body::{Body, Bytes},
body::Bytes,
extract::{ContentLengthLimit, Extension, Path},
handler::{delete, get, Handler},
http::StatusCode,
response::IntoResponse,
route,
routing::{BoxRoute, RoutingDsl},
routing::{BoxRoute, Router},
};
use std::{
borrow::Cow,
Expand Down Expand Up @@ -108,7 +108,7 @@ async fn list_keys(Extension(state): Extension<SharedState>) -> String {
.join("\n")
}

fn admin_routes() -> BoxRoute<Body> {
fn admin_routes() -> Router<BoxRoute> {
async fn delete_all_keys(Extension(state): Extension<SharedState>) {
state.write().unwrap().db.clear();
}
Expand Down
1 change: 0 additions & 1 deletion examples/multipart-form/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use axum::{
handler::get,
response::Html,
route,
routing::RoutingDsl,
};
use std::net::SocketAddr;

Expand Down
4 changes: 1 addition & 3 deletions examples/oauth/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ use axum::{
handler::get,
http::{header::SET_COOKIE, HeaderMap, Response},
response::{IntoResponse, Redirect},
route,
routing::RoutingDsl,
AddExtensionLayer,
route, AddExtensionLayer,
};
use oauth2::{
basic::BasicClient, reqwest::async_http_client, AuthUrl, AuthorizationCode, ClientId,
Expand Down
4 changes: 1 addition & 3 deletions examples/sessions/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ use axum::{
StatusCode,
},
response::IntoResponse,
route,
routing::RoutingDsl,
AddExtensionLayer,
route, AddExtensionLayer,
};
use serde::{Deserialize, Serialize};
use std::net::SocketAddr;
Expand Down
2 changes: 1 addition & 1 deletion examples/sse/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use axum::{
handler::get,
http::StatusCode,
response::sse::{sse, Event, Sse},
routing::{nest, RoutingDsl},
routing::nest,
};
use futures::stream::{self, Stream};
use std::{convert::Infallible, net::SocketAddr, time::Duration};
Expand Down
5 changes: 1 addition & 4 deletions examples/static-file-server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
//! cargo run -p example-static-file-server
//! ```

use axum::{
http::StatusCode,
routing::{nest, RoutingDsl},
};
use axum::{http::StatusCode, routing::nest};
use std::net::SocketAddr;
use tower_http::{services::ServeDir, trace::TraceLayer};

Expand Down
1 change: 0 additions & 1 deletion examples/templates/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ use axum::{
http::{Response, StatusCode},
response::{Html, IntoResponse},
route,
routing::RoutingDsl,
};
use std::{convert::Infallible, net::SocketAddr};

Expand Down
6 changes: 3 additions & 3 deletions examples/testing/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
//! ```

use axum::{
body::Body,
handler::{get, post},
route,
routing::{BoxRoute, RoutingDsl},
routing::{BoxRoute, Router},
Json,
};
use tower_http::trace::TraceLayer;
Expand All @@ -34,7 +33,7 @@ async fn main() {
/// Having a function that produces our app makes it easy to call it from tests
/// without having to create an HTTP server.
#[allow(dead_code)]
fn app() -> BoxRoute<Body> {
fn app() -> Router<BoxRoute> {
route("/", get(|| async { "Hello, World!" }))
.route(
"/json",
Expand All @@ -50,6 +49,7 @@ fn app() -> BoxRoute<Body> {
#[cfg(test)]
mod tests {
use super::*;
use axum::body::Body;
use axum::http::{self, Request, StatusCode};
use serde_json::{json, Value};
use std::net::{SocketAddr, TcpListener};
Expand Down
4 changes: 1 addition & 3 deletions examples/todos/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ use axum::{
handler::{get, patch},
http::StatusCode,
response::IntoResponse,
route,
routing::RoutingDsl,
Json,
route, Json,
};
use serde::{Deserialize, Serialize};
use std::{
Expand Down
4 changes: 1 addition & 3 deletions examples/tokio-postgres/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ use axum::{
extract::{Extension, FromRequest, RequestParts},
handler::get,
http::StatusCode,
route,
routing::RoutingDsl,
AddExtensionLayer,
route, AddExtensionLayer,
};
use bb8::{Pool, PooledConnection};
use bb8_postgres::PostgresConnectionManager;
Expand Down
2 changes: 1 addition & 1 deletion examples/tracing-aka-logging/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//! cargo run -p example-tracing-aka-logging
//! ```

use axum::{handler::get, response::Html, route, routing::RoutingDsl};
use axum::{handler::get, response::Html, route};
use std::net::SocketAddr;
use tower_http::trace::TraceLayer;

Expand Down
1 change: 0 additions & 1 deletion examples/unix-domain-socket/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use axum::{
handler::get,
http::{Method, Request, StatusCode, Uri},
route,
routing::RoutingDsl,
};
use futures::ready;
use hyper::{
Expand Down
1 change: 0 additions & 1 deletion examples/versioning/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ use axum::{
http::{Response, StatusCode},
response::IntoResponse,
route,
routing::RoutingDsl,
};
use std::collections::HashMap;
use std::net::SocketAddr;
Expand Down
2 changes: 1 addition & 1 deletion examples/websockets/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use axum::{
handler::get,
http::StatusCode,
response::IntoResponse,
routing::{nest, RoutingDsl},
routing::nest,
};
use std::net::SocketAddr;
use tower_http::{
Expand Down
20 changes: 10 additions & 10 deletions src/extract/connect_info.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//! Extractor for getting connection information from a client.
//!
//! See [`RoutingDsl::into_make_service_with_connect_info`] for more details.
//! See [`Router::into_make_service_with_connect_info`] for more details.
//!
//! [`RoutingDsl::into_make_service_with_connect_info`]: crate::routing::RoutingDsl::into_make_service_with_connect_info
//! [`Router::into_make_service_with_connect_info`]: crate::routing::Router::into_make_service_with_connect_info

use super::{Extension, FromRequest, RequestParts};
use async_trait::async_trait;
Expand All @@ -19,10 +19,10 @@ use tower_http::add_extension::AddExtension;

/// A [`MakeService`] created from a router.
///
/// See [`RoutingDsl::into_make_service_with_connect_info`] for more details.
/// See [`Router::into_make_service_with_connect_info`] for more details.
///
/// [`MakeService`]: tower::make::MakeService
/// [`RoutingDsl::into_make_service_with_connect_info`]: crate::routing::RoutingDsl::into_make_service_with_connect_info
/// [`Router::into_make_service_with_connect_info`]: crate::routing::Router::into_make_service_with_connect_info
pub struct IntoMakeServiceWithConnectInfo<S, C> {
svc: S,
_connect_info: PhantomData<fn() -> C>,
Expand Down Expand Up @@ -54,9 +54,9 @@ where
/// The goal for this trait is to allow users to implement custom IO types that
/// can still provide the same connection metadata.
///
/// See [`RoutingDsl::into_make_service_with_connect_info`] for more details.
/// See [`Router::into_make_service_with_connect_info`] for more details.
///
/// [`RoutingDsl::into_make_service_with_connect_info`]: crate::routing::RoutingDsl::into_make_service_with_connect_info
/// [`Router::into_make_service_with_connect_info`]: crate::routing::Router::into_make_service_with_connect_info
pub trait Connected<T> {
/// The connection information type the IO resources generates.
type ConnectInfo: Clone + Send + Sync + 'static;
Expand Down Expand Up @@ -104,12 +104,12 @@ opaque_future! {
/// Extractor for getting connection information produced by a [`Connected`].
///
/// Note this extractor requires you to use
/// [`RoutingDsl::into_make_service_with_connect_info`] to run your app
/// [`Router::into_make_service_with_connect_info`] to run your app
/// otherwise it will fail at runtime.
///
/// See [`RoutingDsl::into_make_service_with_connect_info`] for more details.
/// See [`Router::into_make_service_with_connect_info`] for more details.
///
/// [`RoutingDsl::into_make_service_with_connect_info`]: crate::routing::RoutingDsl::into_make_service_with_connect_info
/// [`Router::into_make_service_with_connect_info`]: crate::routing::Router::into_make_service_with_connect_info
#[derive(Clone, Copy, Debug)]
pub struct ConnectInfo<T>(pub T);

Expand All @@ -131,7 +131,7 @@ where
mod tests {
use super::*;
use crate::Server;
use crate::{handler::get, route, routing::RoutingDsl};
use crate::{handler::get, route};
use std::net::{SocketAddr, TcpListener};

#[tokio::test]
Expand Down
1 change: 0 additions & 1 deletion src/extract/content_length_limit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use std::ops::Deref;
/// extract::ContentLengthLimit,
/// handler::post,
/// route,
/// routing::RoutingDsl
/// };
///
/// async fn handler(body: ContentLengthLimit<String, 1024>) {
Expand Down
1 change: 0 additions & 1 deletion src/extract/extension.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ use std::ops::Deref;
/// extract::Extension,
/// handler::get,
/// route,
/// routing::RoutingDsl
/// };
/// use std::sync::Arc;
///
Expand Down
1 change: 0 additions & 1 deletion src/extract/extractor_middleware.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ use tower::{BoxError, Layer, Service};
/// extract::{extractor_middleware, FromRequest, RequestParts},
/// handler::{get, post},
/// route,
/// routing::RoutingDsl
/// };
/// use http::StatusCode;
/// use async_trait::async_trait;
Expand Down
1 change: 0 additions & 1 deletion src/extract/form.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ use tower::BoxError;
/// extract::Form,
/// handler::post,
/// route,
/// routing::RoutingDsl
/// };
/// use serde::Deserialize;
///
Expand Down
Loading