123456789101112131415161718192021222324252627282930 |
- use serde::{Deserialize, Serialize};
-
- #[derive(Serialize, Deserialize, Debug)]
- pub struct OutgoingGist {
- pub title: String,
- pub body: String,
- }
-
- #[derive(Serialize, Deserialize, Debug)]
- pub struct IncomingGist {
- pub id: i32,
- pub title: String,
- pub body: String,
- }
-
- pub fn create_gist(title: &str, body: &str) -> Result<IncomingGist, Box<std::error::Error>> {
- let client = reqwest::Client::new();
- let gist = OutgoingGist {
- title: title.to_string(),
- body: body.to_string(),
- };
-
- let resp: IncomingGist = client
- .post("http://localhost:8000/api/gists")
- .json(&gist)
- .send()?
- .json()?;
-
- Ok(resp)
- }
|