123456789101112131415161718192021222324252627282930313233343536373839404142 |
- use chrono::NaiveDateTime;
- use serde::{Deserialize, Serialize};
-
- #[derive(Serialize, Deserialize, Debug)]
- pub struct OutgoingSnippet {
- pub title: String,
- pub body: String,
- pub formatted_body: String,
- pub filetype: String,
- }
-
- #[derive(Serialize, Deserialize, Debug)]
- pub struct IncomingSnippet {
- pub id: i32,
- pub title: String,
- pub body: String,
- pub created_at: NaiveDateTime,
- }
-
- #[derive(Debug)]
- pub struct ServerConfig {
- pub hostname: String,
- pub protocol: String,
- pub port: i32,
- }
-
- pub fn create_snippet(
- snippet: OutgoingSnippet,
- config: &ServerConfig,
- ) -> Result<IncomingSnippet, Box<std::error::Error>> {
- let client = reqwest::Client::new();
- let resp: IncomingSnippet = client
- .post(&format!(
- "{}://{}:{}/api/snippets",
- config.protocol, config.hostname, config.port,
- ))
- .json(&snippet)
- .send()?
- .json()?;
-
- Ok(resp)
- }
|