1
0
mirror of https://github.com/actix/examples synced 2025-06-26 17:17:42 +02:00

v3 examples (#364)

This commit is contained in:
Rob Ede
2020-09-12 16:49:45 +01:00
committed by GitHub
parent 3f2b2708c3
commit 49e29a5751
112 changed files with 251 additions and 333 deletions

View File

@ -2,16 +2,11 @@
name = "basics"
version = "2.0.0"
authors = ["Nikolay Kim <fafhrd91@gmail.com>"]
workspace = ".."
edition = "2018"
[dependencies]
actix-rt = "1.0.0"
actix-web = "2.0.0"
actix-files = "0.2.1"
actix-session = "0.3.0"
actix-utils = "1.0.3"
futures = "0.3.1"
actix-web = "3"
actix-files = "0.3"
actix-session = "0.4"
actix-utils = "2"
env_logger = "0.7"
bytes = "0.5"

View File

@ -1,17 +1,12 @@
#[macro_use]
extern crate actix_web;
use std::{env, io};
use actix_files as fs;
use actix_session::{CookieSession, Session};
use actix_utils::mpsc;
use actix_web::http::{header, Method, StatusCode};
use actix_web::{
error, guard, middleware, web, App, Error, HttpRequest, HttpResponse, HttpServer,
Result,
error, get, guard, middleware, web, App, Error, HttpRequest, HttpResponse,
HttpServer, Result,
};
use bytes::Bytes;
use std::{env, io};
/// favicon handler
#[get("/favicon")]
@ -50,21 +45,24 @@ async fn response_body(path: web::Path<String>) -> HttpResponse {
let text = format!("Hello {}!", *path);
let (tx, rx_body) = mpsc::channel();
let _ = tx.send(Ok::<_, Error>(Bytes::from(text)));
let _ = tx.send(Ok::<_, Error>(web::Bytes::from(text)));
HttpResponse::Ok().streaming(rx_body)
}
/// handler with path parameters like `/user/{name}/`
async fn with_param(req: HttpRequest, path: web::Path<(String,)>) -> HttpResponse {
async fn with_param(
req: HttpRequest,
web::Path((name,)): web::Path<(String,)>,
) -> HttpResponse {
println!("{:?}", req);
HttpResponse::Ok()
.content_type("text/plain")
.body(format!("Hello {}!", path.0))
.body(format!("Hello {}!", name))
}
#[actix_rt::main]
#[actix_web::main]
async fn main() -> io::Result<()> {
env::set_var("RUST_LOG", "actix_web=debug,actix_server=info");
env_logger::init();