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

simplifies the front-page examples.

This commit is contained in:
Cameron Dershem
2019-06-19 14:24:31 -04:00
parent 2011f100a5
commit da969fed1f
4 changed files with 15 additions and 16 deletions

View File

@ -14,8 +14,8 @@ fn index() -> HttpResponse {
.body(include_str!("../static/form.html"))
}
fn register(params: web::Form<Register>) -> impl Responder {
format!("Hello {} from {}!", params.username, params.country)
fn register(form: web::Form<Register>) -> impl Responder {
format!("Hello {} from {}!", form.username, form.country)
}
fn main() {

View File

@ -9,8 +9,8 @@ fn greet(req: HttpRequest) -> impl Responder {
fn main() {
HttpServer::new(|| {
App::new()
.service(web::resource("/").to(greet))
.service(web::resource("/{name}").to(greet))
.route("/", web::get().to(greet))
.route("/{name}", web::get().to(greet))
})
.bind("127.0.0.1:8088")
.unwrap()

View File

@ -9,19 +9,19 @@ struct Event {
tags: Vec<String>,
}
fn store_event_in_db(timestamp: f64, kind: String, tags: Vec<String>) -> Event {
fn store_in_db(timestamp: f64, kind: &String, tags: &Vec<String>) -> Event {
// store item in db and get new_event
// use id to lookup item
Event {
id: Some(1),
timestamp: timestamp,
kind: kind,
tags: tags,
kind: kind.to_string(),
tags: tags.to_vec(),
}
}
fn capture_event(evt: web::Json<Event>) -> impl Responder {
let new_event = store_event_in_db(evt.timestamp, evt.kind.clone(), evt.tags.clone());
let new_event = store_in_db(evt.timestamp, &evt.kind, &evt.tags);
format!("got event {}", new_event.id.unwrap())
}