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 681B

123456789101112131415161718192021222324252627282930
  1. use serde::{Deserialize, Serialize};
  2. #[derive(Serialize, Deserialize, Debug)]
  3. pub struct OutgoingGist {
  4. pub title: String,
  5. pub body: String,
  6. }
  7. #[derive(Serialize, Deserialize, Debug)]
  8. pub struct IncomingGist {
  9. pub id: i32,
  10. pub title: String,
  11. pub body: String,
  12. }
  13. pub fn create_gist(title: &str, body: &str) -> Result<IncomingGist, Box<std::error::Error>> {
  14. let client = reqwest::Client::new();
  15. let gist = OutgoingGist {
  16. title: title.to_string(),
  17. body: body.to_string(),
  18. };
  19. let resp: IncomingGist = client
  20. .post("http://localhost:8000/api/gists")
  21. .json(&gist)
  22. .send()?
  23. .json()?;
  24. Ok(resp)
  25. }