Skip to content

Commit 42e4dfc

Browse files
authored
fix http-axum example code (#799)
1 parent 9f8f250 commit 42e4dfc

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

examples/http-axum/src/main.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,21 @@
1-
//! This is an example function that leverages the Lambda Rust runtime's HTTP support
1+
//! This is an example function that leverages the Lambda Rust runtime HTTP support
22
//! and the [axum](https://docs.rs/axum/latest/axum/index.html) web framework. The
33
//! runtime HTTP support is backed by the [tower::Service](https://docs.rs/tower-service/0.3.2/tower_service/trait.Service.html)
4-
//! trait. Axum applications are also backed by the `tower::Service` trait. That means
4+
//! trait. Axum's applications are also backed by the `tower::Service` trait. That means
55
//! that it is fairly easy to build an Axum application and pass the resulting `Service`
66
//! implementation to the Lambda runtime to run as a Lambda function. By using Axum instead
77
//! of a basic `tower::Service` you get web framework niceties like routing, request component
88
//! extraction, validation, etc.
9-
use std::env::set_var;
109
use axum::http::StatusCode;
11-
use lambda_http::{
12-
run,
13-
Error,
14-
};
1510
use axum::{
1611
extract::Path,
1712
response::Json,
18-
Router,
1913
routing::{get, post},
14+
Router,
2015
};
21-
use serde_json::{Value, json};
16+
use lambda_http::{run, Error};
17+
use serde_json::{json, Value};
18+
use std::env::set_var;
2219

2320
async fn root() -> Json<Value> {
2421
Json(json!({ "msg": "I am GET /" }))
@@ -36,12 +33,15 @@ async fn post_foo_name(Path(name): Path<String>) -> Json<Value> {
3633
Json(json!({ "msg": format!("I am POST /foo/:name, name={name}") }))
3734
}
3835

39-
/// Example on how to return status codes and data from a Axum function
40-
async fn health_check() -> (StatusCode, &str) {
41-
let healthy = false;
36+
/// Example on how to return status codes and data from an Axum function
37+
async fn health_check() -> (StatusCode, String) {
38+
let health = true;
4239
match health {
43-
true => {(StatusCode::OK, "Healthy!")},
44-
false => {(StatusCode::INTERNAL_SERVER_ERROR, "Not healthy!")}
40+
true => (StatusCode::OK, "Healthy!".to_string()),
41+
false => (
42+
StatusCode::INTERNAL_SERVER_ERROR,
43+
"Not healthy!".to_string(),
44+
),
4545
}
4646
}
4747

@@ -51,7 +51,7 @@ async fn main() -> Result<(), Error> {
5151
// Remove if you want the first section of the url to be the stage name of the API Gateway
5252
// i.e with: `GET /test-stage/todo/id/123` without: `GET /todo/id/123`
5353
set_var("AWS_LAMBDA_HTTP_IGNORE_STAGE_IN_PATH", "true");
54-
54+
5555
// required to enable CloudWatch error logging by the runtime
5656
tracing_subscriber::fmt()
5757
.with_max_level(tracing::Level::INFO)

0 commit comments

Comments
 (0)