feignhttp icon indicating copy to clipboard operation
feignhttp copied to clipboard

Add parameters inside FeignClient

Open ajuvercr opened this issue 3 years ago • 0 comments

Add parameters inside struct types to handle dynamic URL's betters, example:

#[derive(Feign)]
#[feign(headers = "Accept: {accept}")]
struct Github {
    #[feign_path("owner")]
    user: &'static str,
    #[feign_path]
    repo: &'static str,
    #[param]
    accept: &'static str,
}

#[feign(url = "https://api.github.com/repos/{owner}/{repo}")]
impl Github {
    #[get]
    async fn home(&self) -> feignhttp::Result<String> {}

    #[get("/repos/{owner}/{repo}", headers = "accept: application/json")]
    async fn repository(&self) -> feignhttp::Result<String> {}
}

This makes it easier to have a Github instance that always sends requests with the same headers to the same dynamic URL.

Fixes #6.

Changed:

  • Add FeignClient trait + Derive
  • Add #[path] #[query] #[param] #[header] parameters inside FeignClients

PS: The code is not the greatest and new tests are missing, but if you feel like merging this PR I can easily add those.

ajuvercr avatar Nov 16 '22 20:11 ajuvercr