Skip to content

Commit b1a8b87

Browse files
dglsparsonsecklf
andauthored
Change impl IntoResponse into Response<Body> (#1)
* Rework to allow merging api endpoints * Rework all examples and simplify structure * remove `IntoResponse` --------- Co-authored-by: Florentin / 珞辰 <[email protected]>
1 parent 9a65014 commit b1a8b87

File tree

19 files changed

+73
-139
lines changed

19 files changed

+73
-139
lines changed

examples/cron/Cargo.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/cron/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ serde = { version = "1.0.145", features = ["derive"] }
1212
serde_json = { version = "1.0.86", features = ["raw_value"] }
1313
serde_derive = "1.0.9"
1414
rand = "0.8.5"
15-
vercel_runtime = "0.1.4"
15+
vercel_runtime = { version = "0.1.4", path = "../../vercel_runtime" }
1616
slack-morphism = { version = "1.2.2", features = ["hyper"] }
1717

1818
[[bin]]

examples/cron/api/cron.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
use slack_morphism::{errors::SlackClientError, prelude::*};
2-
use vercel_runtime::{
3-
lambda_http::{http::StatusCode, Response},
4-
run, Error, IntoResponse, Request,
5-
};
2+
use vercel_runtime::{run, Body, Error, Request, Response, StatusCode};
63

74
#[derive(Debug, Clone)]
85
pub struct SlackMessage {}
@@ -31,12 +28,12 @@ impl<T: SlackClientHttpConnector + Send + Sync> Lambda<'_, T> {
3128
self.slack.chat_post_message(&post_chat_req).await
3229
}
3330

34-
pub async fn handler(&self, _req: Request) -> Result<impl IntoResponse, Error> {
31+
pub async fn handler(&self, _req: Request) -> Result<Response<Body>, Error> {
3532
let message = SlackMessage {};
3633

3734
self.post_message(&message, "#general").await?;
3835

39-
let response = Response::builder().status(StatusCode::OK).body(())?;
36+
let response = Response::builder().status(StatusCode::OK).body(().into())?;
4037
Ok(response)
4138
}
4239
}

examples/merged/Cargo.lock

Lines changed: 0 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/merged/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ serde = { version = "1.0.145", features = ["derive"] }
1111
serde_json = { version = "1.0.86", features = ["raw_value"] }
1212
serde_derive = "1.0.9"
1313
rand = "0.8.5"
14-
vercel_runtime = "0.1.4"
14+
vercel_runtime = { version = "0.1.4", path = "../../vercel_runtime" }
1515
url = "2.3.1"
1616

1717
[lib]

examples/merged/api/bar/baz.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
use runtime_demo::choose_starter;
22
use serde_json::json;
3-
use vercel_runtime::{
4-
lambda_http::{http::StatusCode, Response},
5-
Error, IntoResponse, Request,
6-
};
3+
use vercel_runtime::{Body, Error, Request, Response, StatusCode};
74

8-
pub async fn handler(_req: Request) -> Result<impl IntoResponse, Error> {
5+
pub async fn handler(_req: Request) -> Result<Response<Body>, Error> {
96
dbg!(_req);
107
let starter = choose_starter();
118
let response = Response::builder()
@@ -15,7 +12,8 @@ pub async fn handler(_req: Request) -> Result<impl IntoResponse, Error> {
1512
json!({
1613
"message": format!("I choose you, {}!", starter),
1714
})
18-
.to_string(),
15+
.to_string()
16+
.into(),
1917
)?;
2018

2119
Ok(response)

examples/merged/api/foo.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
use runtime_demo::choose_starter;
22
use serde_json::json;
3-
use vercel_runtime::{
4-
lambda_http::{http::StatusCode, Response},
5-
Error, IntoResponse, Request,
6-
};
3+
use vercel_runtime::{Body, Error, Request, Response, StatusCode};
74

8-
pub async fn handler(_req: Request) -> Result<impl IntoResponse, Error> {
5+
pub async fn handler(_req: Request) -> Result<Response<Body>, Error> {
96
dbg!(_req);
107
let starter = choose_starter();
118
let response = Response::builder()
@@ -15,7 +12,8 @@ pub async fn handler(_req: Request) -> Result<impl IntoResponse, Error> {
1512
json!({
1613
"message": format!("I choose you, {}!", starter),
1714
})
18-
.to_string(),
15+
.to_string()
16+
.into(),
1917
)?;
2018

2119
Ok(response)

examples/merged/api/index.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
use vercel_runtime::{run, Error, IntoResponse, Request};
1+
use vercel_runtime::{run, Body, Error, Request, Response};
22

33
#[path = "../api/bar/baz.rs"]
44
mod api_bar_baz;
55

66
#[path = "../api/foo.rs"]
77
mod api_foo;
88

9-
async fn process_request(request: Request) -> Result<impl IntoResponse, Error> {
9+
async fn process_request(request: Request) -> Result<Response<Body>, Error> {
1010
let path = request.uri().path();
1111

1212
match path {

examples/nextjs/Cargo.lock

Lines changed: 3 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/nextjs/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ serde = { version = "1.0.145", features = ["derive"] }
1212
serde_json = { version = "1.0.86", features = ["raw_value"] }
1313
serde_derive = "1.0.9"
1414
rand = "0.8.5"
15-
vercel_runtime = "0.1.4"
15+
vercel_runtime = { version = "0.1.4", path = "../../vercel_runtime" }
1616
oorandom = "11.1.3"
1717

1818
[[bin]]

0 commit comments

Comments
 (0)