happi
:)This includes a CI/CD pipeline, README templating, and cargo-make scripts.
Using an example of https://reqres.in/, a happi
implementation of this would look something like:
```rust pub fn main() -> Result<(), dyn std::error::Error> { let reqres = ReqResApi(reqwest::blocking::Client::new());
let userpage = reqres.getall_users(None)?;
println!("{:#?}", user_page); }
// This is the real client that hits the API
pub struct ReqResApi(#[client] hyper::Client);
// This is a trait for the user
resource that happi
// will implement for ReqResApi
.
//
// When you want to use this resource, your function can
// accept an impl reqres::UserResource
, accepting the real
// deal or a mock when you write tests.
api(ReqResApi),
resource("/users"),
responds(200, json),
)]
pub trait UserResource {
#[get]
pub fn getallusers(&self, #[query] page: Option
#[get( "/{id}", responds(404, unit), when(status == 404, invoke = |resp| Ok(None)), )] pub fn getuser(&self, id: u32) -> Result
pub struct User { id: u32, firstname: String, lastname: String, avatar: String, }
pub struct UserPage {
page: u32,
perpage: u32,
total: u32,
totalpages: u32,
data: Vec
Licensed under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.