1
0
mirror of https://github.com/actix/actix-website synced 2025-06-27 07:29:02 +02:00

Requests is done-ish.

This commit is contained in:
Cameron Dershem
2019-06-26 01:27:17 -04:00
parent be68e418b0
commit d7d4392d87
6 changed files with 69 additions and 47 deletions

View File

@ -9,3 +9,4 @@ serde_json = "1.0"
actix-web = "1.0"
futures = "0.1"
bytes = "0.4"
actix-multipart = "0.1"

View File

@ -3,8 +3,9 @@ pub mod manual;
pub mod multipart;
pub mod streaming;
pub mod urlencoded;
// <json-request>
use actix_web::{web, App, Result};
use actix_web::{web, App, HttpServer, Result};
use serde::Deserialize;
#[derive(Deserialize)]
@ -18,6 +19,10 @@ fn index(info: web::Json<Info>) -> Result<String> {
}
fn main() {
App::new().route("/index.html", web::post().to(index));
HttpServer::new(|| App::new().route("/", web::post().to(index)))
.bind("127.0.0.1:8088")
.unwrap()
.run()
.unwrap();
}
// </json-request>

View File

@ -43,5 +43,11 @@ pub fn index_manual(
// </json-manual>
pub fn main() {
App::new().route("/", web::post().to_async(index_manual));
use actix_web::HttpServer;
HttpServer::new(|| App::new().route("/", web::post().to_async(index_manual)))
.bind("127.0.0.1:8088")
.unwrap()
.run()
.unwrap();
}

View File

@ -1,15 +1,26 @@
// <streaming>
// use actix_web::{error, web, Error, HttpResponse};
// use futures::{future::result, Future, Stream};
use actix_web::{error, web, Error, HttpResponse};
use futures::{future::result, Future, Stream};
// pub fn index(payload: web::Payload) -> Box<Future<Item = HttpResponse, Error = Error>> {
// payload
// .from_err()
// .fold((), |_, chunk| {
// println!("Chunk: {:?}", chunk);
// result::<_, error::PayloadError>(Ok(()))
// })
// .map(|_| HttpResponse::Ok().finish())
// .responder()
// }
pub fn index(payload: web::Payload) -> Box<Future<Item = HttpResponse, Error = Error>> {
Box::new(
payload
.from_err()
.fold((), |_, chunk| {
println!("Chunk: {:?}", chunk);
result::<_, error::PayloadError>(Ok(()))
})
.map(|_| HttpResponse::Ok().into()),
)
}
// </streaming>
pub fn main() {
use actix_web::{App, HttpServer};
HttpServer::new(|| App::new().route("/", web::post().to_async(index)))
.bind("127.0.0.1:8088")
.unwrap()
.run()
.unwrap();
}

View File

@ -1,22 +1,23 @@
// <urlencoded>
// use actix_web::{Error, HttpRequest, HttpResponse};
// use futures::future::{ok, Future};
// use serde::Deserialize;
use actix_web::{web, HttpResponse};
use serde::Deserialize;
// #[derive(Deserialize)]
// struct FormData {
// username: String,
// }
#[derive(Deserialize)]
struct FormData {
username: String,
}
// fn index(req: &HttpRequest) -> Box<Future<Item = HttpResponse, Error = Error>> {
// req.urlencoded::<FormData>() // <- get UrlEncoded future
// .from_err()
// .and_then(|data| {
// // <- deserialized instance
// println!("USERNAME: {:?}", data.username);
// ok(HttpResponse::Ok().into())
// })
// .responder()
// }
fn index(form: web::Form<FormData>) -> HttpResponse {
HttpResponse::Ok().body(format!("username: {}", form.username))
}
// </urlencoded>
pub fn main() {}
pub fn main() {
use actix_web::{App, HttpServer};
HttpServer::new(|| App::new().route("/", web::post().to(index)))
.bind("127.0.0.1:8088")
.unwrap()
.run()
.unwrap();
}