Parse JSON from post request

Accept a post request and try to parse it expecting the data is
formated in JSON.
This commit is contained in:
finga 2021-02-02 11:05:50 +01:00
commit d8ca63ab37
4 changed files with 1152 additions and 0 deletions

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
/target

1116
Cargo.lock generated Normal file

File diff suppressed because it is too large Load diff

11
Cargo.toml Normal file
View file

@ -0,0 +1,11 @@
[package]
name = "webhookey"
version = "0.1.0"
authors = ["finga <coding@onders.org>"]
edition = "2018"
[dependencies]
rocket = "0.4"
rocket_contrib = { version = "0.4", default-features = false, features = ["json"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"

24
src/main.rs Normal file
View file

@ -0,0 +1,24 @@
#![feature(proc_macro_hygiene, decl_macro)]
use rocket::{get, post, routes};
use rocket_contrib::json::Json;
use serde::{Deserialize, Serialize};
#[derive(Debug, Deserialize, Serialize)]
struct Data (serde_json::Value);
#[get("/")]
fn index() -> &'static str {
"Hello, webhookey!"
}
#[post("/", format = "json", data = "<data>")]
fn receive_hook(data: Json<Data>) -> String {
format!("data: {:?}", data)
}
fn main() {
rocket::ignite()
.mount("/", routes![index, receive_hook])
.launch();
}