The CLI frontend to a gist server written in Rust
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

client.rs 924B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. use chrono::NaiveDateTime;
  2. use serde::{Deserialize, Serialize};
  3. #[derive(Serialize, Deserialize, Debug)]
  4. pub struct OutgoingGist {
  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 IncomingGist {
  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_gist(
  24. gist: OutgoingGist,
  25. config: &ServerConfig,
  26. ) -> Result<IncomingGist, Box<std::error::Error>> {
  27. let client = reqwest::Client::new();
  28. let resp: IncomingGist = client
  29. .post(&format!(
  30. "{}://{}:{}/api/gists",
  31. config.protocol, config.hostname, config.port,
  32. ))
  33. .json(&gist)
  34. .send()?
  35. .json()?;
  36. Ok(resp)
  37. }