The CLI frontend to a gist server written in Rust
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

client.rs 951B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. use chrono::NaiveDateTime;
  2. use serde::{Deserialize, Serialize};
  3. #[derive(Serialize, Deserialize, Debug)]
  4. pub struct OutgoingSnippet {
  5. pub title: String,
  6. pub body: String,
  7. pub formatted_body: String,
  8. pub filetype: String,
  9. }
  10. #[derive(Serialize, Deserialize, Debug)]
  11. pub struct IncomingSnippet {
  12. pub id: i32,
  13. pub title: String,
  14. pub body: String,
  15. pub created_at: NaiveDateTime,
  16. }
  17. #[derive(Debug)]
  18. pub struct ServerConfig {
  19. pub hostname: String,
  20. pub protocol: String,
  21. pub port: i32,
  22. }
  23. pub fn create_snippet(
  24. snippet: OutgoingSnippet,
  25. config: &ServerConfig,
  26. ) -> Result<IncomingSnippet, Box<std::error::Error>> {
  27. let client = reqwest::Client::new();
  28. let resp: IncomingSnippet = client
  29. .post(&format!(
  30. "{}://{}:{}/api/snippets",
  31. config.protocol, config.hostname, config.port,
  32. ))
  33. .json(&snippet)
  34. .send()?
  35. .json()?;
  36. Ok(resp)
  37. }