Skip to content

Commit 77ad45a

Browse files
committed
Fix issues in http-axum example
1 parent 6586fd3 commit 77ad45a

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

examples/http-axum/src/main.rs

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,16 @@
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,12 @@ 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) {
36+
/// Example on how to return status codes and data from an Axum function
37+
async fn health_check() -> (StatusCode, &'static str) {
4138
let healthy = false;
42-
match health {
43-
true => {(StatusCode::OK, "Healthy!")},
44-
false => {(StatusCode::INTERNAL_SERVER_ERROR, "Not healthy!")}
39+
match healthy {
40+
true => (StatusCode::OK, "Healthy!"),
41+
false => (StatusCode::INTERNAL_SERVER_ERROR, "Not healthy!"),
4542
}
4643
}
4744

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

0 commit comments

Comments
 (0)