Axum 0.4.0 (#168)
* axum 0.4.0 Signed-off-by: andrew webber (personal) <andrewvwebber@googlemail.com>
This commit is contained in:
parent
ba798f30cb
commit
ae83a69f7f
|
@ -45,7 +45,7 @@ bytes = { version = "^1.0", optional = true }
|
|||
futures = { version = "^0.3", optional = true }
|
||||
http = { version = "0.2", optional = true }
|
||||
hyper = { version = "^0.14", optional = true }
|
||||
axum-lib = { version = "^0.2", optional = true, package = "axum" }
|
||||
axum-lib = { version = "^0.4", optional = true , package="axum"}
|
||||
http-body = { version = "^0.4", optional = true }
|
||||
poem-lib = { version = "=1.2.34", optional = true, package = "poem" }
|
||||
|
||||
|
|
|
@ -2,11 +2,11 @@
|
|||
name = "axum-example"
|
||||
version = "0.3.0"
|
||||
authors = ["Andrew Webber <andrewvwebber@googlemail.com>"]
|
||||
edition = "2018"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
cloudevents-sdk = { path = "../..", features = ["axum"] }
|
||||
axum = "^0.2"
|
||||
axum = "^0.4"
|
||||
http = "^0.2"
|
||||
tokio = { version = "^1", features = ["full"] }
|
||||
tracing = "^0.1"
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
use axum::{
|
||||
handler::{get, post},
|
||||
routing::BoxRoute,
|
||||
routing::{get, post},
|
||||
Router,
|
||||
};
|
||||
use cloudevents::Event;
|
||||
|
@ -8,7 +7,7 @@ use http::StatusCode;
|
|||
use std::net::SocketAddr;
|
||||
use tower_http::trace::TraceLayer;
|
||||
|
||||
fn echo_app() -> Router<BoxRoute> {
|
||||
fn echo_app() -> Router {
|
||||
Router::new()
|
||||
.route("/", get(|| async { "hello from cloudevents server" }))
|
||||
.route(
|
||||
|
@ -19,7 +18,6 @@ fn echo_app() -> Router<BoxRoute> {
|
|||
}),
|
||||
)
|
||||
.layer(TraceLayer::new_for_http())
|
||||
.boxed()
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
|
|
|
@ -8,14 +8,13 @@
|
|||
//! ```
|
||||
//! use axum_lib as axum;
|
||||
//! use axum::{
|
||||
//! handler::{get, post},
|
||||
//! routing::BoxRoute,
|
||||
//! routing::{get, post},
|
||||
//! Router,
|
||||
//! };
|
||||
//! use cloudevents::Event;
|
||||
//! use http::StatusCode;
|
||||
//!
|
||||
//! fn app() -> Router<BoxRoute> {
|
||||
//! fn app() -> Router {
|
||||
//! Router::new()
|
||||
//! .route("/", get(|| async { "hello from cloudevents server" }))
|
||||
//! .route(
|
||||
|
@ -25,7 +24,6 @@
|
|||
//! (StatusCode::OK, event)
|
||||
//! }),
|
||||
//! )
|
||||
//! .boxed()
|
||||
//! }
|
||||
//!
|
||||
//! ```
|
||||
|
@ -35,15 +33,14 @@
|
|||
//! ```
|
||||
//! use axum_lib as axum;
|
||||
//! use axum::{
|
||||
//! handler::{get, post},
|
||||
//! routing::BoxRoute,
|
||||
//! routing::{get, post},
|
||||
//! Router,
|
||||
//! };
|
||||
//! use cloudevents::{Event, EventBuilder, EventBuilderV10};
|
||||
//! use http::StatusCode;
|
||||
//! use serde_json::json;
|
||||
//!
|
||||
//! fn app() -> Router<BoxRoute> {
|
||||
//! fn app() -> Router {
|
||||
//! Router::new()
|
||||
//! .route("/", get(|| async { "hello from cloudevents server" }))
|
||||
//! .route(
|
||||
|
@ -70,7 +67,6 @@
|
|||
//! Ok::<Event, (StatusCode, String)>(event)
|
||||
//! }),
|
||||
//! )
|
||||
//! .boxed()
|
||||
//! }
|
||||
//!
|
||||
//! ```
|
||||
|
@ -85,9 +81,8 @@ mod tests {
|
|||
|
||||
use axum::{
|
||||
body::Body,
|
||||
handler::{get, post},
|
||||
http::{self, Request, StatusCode},
|
||||
routing::BoxRoute,
|
||||
routing::{get, post},
|
||||
Router,
|
||||
};
|
||||
use chrono::Utc;
|
||||
|
@ -96,7 +91,7 @@ mod tests {
|
|||
|
||||
use crate::Event;
|
||||
|
||||
fn echo_app() -> Router<BoxRoute> {
|
||||
fn echo_app() -> Router {
|
||||
Router::new()
|
||||
.route("/", get(|| async { "hello from cloudevents server" }))
|
||||
.route(
|
||||
|
@ -106,7 +101,6 @@ mod tests {
|
|||
(StatusCode::OK, event)
|
||||
}),
|
||||
)
|
||||
.boxed()
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
|
|
|
@ -1,22 +1,27 @@
|
|||
use axum_lib as axum;
|
||||
|
||||
use axum::{body::Body, http::Response, response::IntoResponse};
|
||||
use axum::{
|
||||
body::{boxed, BoxBody},
|
||||
http::Response,
|
||||
response::IntoResponse,
|
||||
};
|
||||
use http::{header, StatusCode};
|
||||
use hyper::body::Body;
|
||||
|
||||
use crate::binding::http::builder::adapter::to_response;
|
||||
use crate::event::Event;
|
||||
|
||||
impl IntoResponse for Event {
|
||||
type Body = Body;
|
||||
type BodyError = <Self::Body as axum::body::HttpBody>::Error;
|
||||
|
||||
fn into_response(self) -> Response<Body> {
|
||||
fn into_response(self) -> Response<BoxBody> {
|
||||
match to_response(self) {
|
||||
Ok(resp) => resp,
|
||||
Ok(resp) => {
|
||||
let (parts, body) = resp.into_parts();
|
||||
Response::from_parts(parts, boxed(body))
|
||||
}
|
||||
Err(err) => Response::builder()
|
||||
.status(StatusCode::INTERNAL_SERVER_ERROR)
|
||||
.header(header::CONTENT_TYPE, "text/plain")
|
||||
.body(err.to_string().into())
|
||||
.body(boxed(Body::from(err.to_string())))
|
||||
.unwrap(),
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue