mirror of
https://github.com/actix/actix-website
synced 2025-06-27 15:39:02 +02:00
Requests is done-ish.
This commit is contained in:
@ -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>
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
Reference in New Issue
Block a user