From eaaedb6a0a6d9c7c29a9a56cba1ea5bb8b64af56 Mon Sep 17 00:00:00 2001 From: Jake Swenson Date: Sat, 18 Sep 2021 11:31:47 -0700 Subject: [PATCH] chore: update example --- README.md | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f6bffa6..dcf6f36 100644 --- a/README.md +++ b/README.md @@ -11,13 +11,38 @@ Inspired by [Retrofit] and [Refit] to bring something like them to rust. ## Example ```rust +#[derive(Deserialize, Serialize, Clone)] +pub struct HttpBinResponse { + pub url: String, +} + #[retroqwest::retroqwest] pub trait HttpBin { - #[get::json("/anything")] + #[http::get("/anything")] async fn get_anything(&self) -> Result; - #[get::json("/anything/{name}")] + #[http::get("/anything/{name}")] async fn get_by_name(&self, name: String) -> Result; + + #[http::post("/anything/{name}")] + async fn post_to_name( + &self, + name: String, + #[query] q: bool, + #[json] body: &HttpBinResponse, + ) -> Result; +} + +impl HttpBinClient { + pub fn new(base_uri: String) -> Result { + Self::from_builder(base_uri, ClientBuilder::default()) + } +} + +// This method allows for better code completion +// since `impl HttpBin` is better than the generated struct... +fn build_client(uri: String) -> Result { + Ok(HttpBinClient::new(uri)?) } ```