The CLI frontend to a gist server written in Rust
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

client.rs 869B

1234567891011121314151617181920212223242526272829303132333435363738
  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 filetype: Option<String>,
  8. }
  9. #[derive(Serialize, Deserialize, Debug)]
  10. pub struct IncomingGist {
  11. pub id: i32,
  12. pub title: String,
  13. pub body: String,
  14. pub created_at: NaiveDateTime,
  15. }
  16. pub fn create_gist(
  17. title: &str,
  18. body: &str,
  19. filetype: Option<&str>,
  20. ) -> Result<IncomingGist, Box<std::error::Error>> {
  21. let client = reqwest::Client::new();
  22. let gist = OutgoingGist {
  23. title: title.to_string(),
  24. body: body.to_string(),
  25. filetype: filetype.map(|ft| ft.to_string()),
  26. };
  27. let resp: IncomingGist = client
  28. .post("http://localhost:8000/api/gists")
  29. .json(&gist)
  30. .send()?
  31. .json()?;
  32. Ok(resp)
  33. }