mirror of
https://github.com/actix/actix-website
synced 2025-02-02 12:19:04 +01:00
Update powerful-extractors
This commit is contained in:
parent
789cb0fd1a
commit
8594212533
@ -4,5 +4,6 @@ version = "1.0.0"
|
|||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
actix-web = "1.0"
|
actix-web = "2.0"
|
||||||
|
actix-rt = "1.0"
|
||||||
serde = "1.0"
|
serde = "1.0"
|
||||||
|
@ -20,25 +20,25 @@ fn store_in_db(timestamp: f64, kind: &str, tags: &[String]) -> Event {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn capture_event(evt: web::Json<Event>) -> impl Responder {
|
async fn capture_event(evt: web::Json<Event>) -> impl Responder {
|
||||||
let new_event = store_in_db(evt.timestamp, &evt.kind, &evt.tags);
|
let new_event = store_in_db(evt.timestamp, &evt.kind, &evt.tags);
|
||||||
format!("got event {}", new_event.id.unwrap())
|
format!("got event {}", new_event.id.unwrap())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn index() -> HttpResponse {
|
async fn index() -> HttpResponse {
|
||||||
HttpResponse::Ok()
|
HttpResponse::Ok()
|
||||||
.content_type("text/html; charset=utf-8")
|
.content_type("text/html; charset=utf-8")
|
||||||
.body(include_str!("../static/form.html"))
|
.body(include_str!("../static/form.html"))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
#[actix_rt::main]
|
||||||
|
async fn main() -> std::io::Result<()> {
|
||||||
HttpServer::new(|| {
|
HttpServer::new(|| {
|
||||||
App::new()
|
App::new()
|
||||||
.route("/", web::get().to(index))
|
.route("/", web::get().to(index))
|
||||||
.route("/event", web::post().to(capture_event))
|
.route("/event", web::post().to(capture_event))
|
||||||
})
|
})
|
||||||
.bind("127.0.0.1:8088")
|
.bind("127.0.0.1:8088")?
|
||||||
.unwrap()
|
|
||||||
.run()
|
.run()
|
||||||
.unwrap();
|
.await
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user