mirror of
https://github.com/actix/examples
synced 2025-06-26 09:17:41 +02:00
chore: update deps
This commit is contained in:
@ -7,6 +7,7 @@ edition = "2021"
|
||||
actix-files.workspace = true
|
||||
actix-session = { workspace = true, features = ["cookie-session"] }
|
||||
actix-web.workspace = true
|
||||
actix-web-lab.workspace = true
|
||||
|
||||
async-stream = "0.3"
|
||||
env_logger.workspace = true
|
||||
|
@ -10,6 +10,7 @@ use actix_web::{
|
||||
},
|
||||
middleware, web, App, Either, HttpRequest, HttpResponse, HttpServer, Responder, Result,
|
||||
};
|
||||
use actix_web_lab::extract::Path;
|
||||
use async_stream::stream;
|
||||
|
||||
// NOTE: Not a suitable session key for production.
|
||||
@ -54,8 +55,7 @@ async fn default_handler(req_method: Method) -> Result<impl Responder> {
|
||||
}
|
||||
}
|
||||
|
||||
/// response body
|
||||
async fn response_body(path: web::Path<String>) -> HttpResponse {
|
||||
async fn streaming_response(path: web::Path<String>) -> HttpResponse {
|
||||
let name = path.into_inner();
|
||||
|
||||
HttpResponse::Ok()
|
||||
@ -67,13 +67,13 @@ async fn response_body(path: web::Path<String>) -> HttpResponse {
|
||||
})
|
||||
}
|
||||
|
||||
/// handler with path parameters like `/user/{name}/`
|
||||
async fn with_param(req: HttpRequest, path: web::Path<(String,)>) -> HttpResponse {
|
||||
/// handler with path parameters like `/user/{name}`
|
||||
async fn with_param(req: HttpRequest, Path((name,)): Path<(String,)>) -> HttpResponse {
|
||||
println!("{req:?}");
|
||||
|
||||
HttpResponse::Ok()
|
||||
.content_type(ContentType::plaintext())
|
||||
.body(format!("Hello {}!", path.0))
|
||||
.body(format!("Hello {name}!"))
|
||||
}
|
||||
|
||||
#[actix_web::main]
|
||||
@ -104,7 +104,7 @@ async fn main() -> io::Result<()> {
|
||||
// with path parameters
|
||||
.service(web::resource("/user/{name}").route(web::get().to(with_param)))
|
||||
// async response body
|
||||
.service(web::resource("/async-body/{name}").route(web::get().to(response_body)))
|
||||
.service(web::resource("/async-body/{name}").route(web::get().to(streaming_response)))
|
||||
.service(
|
||||
web::resource("/test").to(|req: HttpRequest| match *req.method() {
|
||||
Method::GET => HttpResponse::Ok(),
|
||||
|
@ -1,5 +1,5 @@
|
||||
[package]
|
||||
name = "error_handling"
|
||||
name = "error-handling"
|
||||
version = "1.0.0"
|
||||
edition = "2021"
|
||||
|
||||
|
Reference in New Issue
Block a user