Skip to content

Commit

Permalink
chore: update example
Browse files Browse the repository at this point in the history
  • Loading branch information
jakeswenson committed Sep 18, 2021
1 parent 5075fe1 commit eaaedb6
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<HttpBinResponse, RetroqwestError>;

#[get::json("/anything/{name}")]
#[http::get("/anything/{name}")]
async fn get_by_name(&self, name: String) -> Result<HttpBinResponse, RetroqwestError>;

#[http::post("/anything/{name}")]
async fn post_to_name(
&self,
name: String,
#[query] q: bool,
#[json] body: &HttpBinResponse,
) -> Result<HttpBinResponse, RetroqwestError>;
}

impl HttpBinClient {
pub fn new(base_uri: String) -> Result<Self, RetroqwestError> {
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<impl HttpBin, retroqwest::RetroqwestError> {
Ok(HttpBinClient::new(uri)?)
}
```

Expand Down

0 comments on commit eaaedb6

Please # to comment.