use std::collections::HashMap;
use lunatic::Mailbox;
use serde::{Deserialize, Serialize};
#[derive(Debug, Serialize, Deserialize)]
struct Post {
id: Option<i32>,
title: String,
body: String,
#[serde(rename = "userId")]
user_id: i32,
}
#[derive(Debug, Serialize, Deserialize)]
struct AnythingResponse<T> {
args: HashMap<String, String>,
data: String,
files: HashMap<String, String>,
form: HashMap<String, String>,
headers: HashMap<String, String>,
json: Option<T>,
method: String,
origin: String,
url: String,
}
#[lunatic::main]
fn main(_: Mailbox<()>) -> Result<(), nightfly::Error> {
let new_post = Post {
id: None,
title: "Nightfly.rs".into(),
body: "https://docs.rs/nightfly".into(),
user_id: 1,
};
let new_post: AnythingResponse<Post> = nightfly::Client::new()
.post("http://eu.httpbin.org/anything")
.json(&new_post)
.send()
.unwrap()
.json()
.unwrap();
println!("{:#?}", new_post);
}