Giter Site home page Giter Site logo

Comments (3)

dxx avatar dxx commented on July 26, 2024

You can see here.

This is an example:

#[derive(Feign)]
pub struct Header {
    #[header]
    pub user_agent: String,
    #[header]
    pub access_token: String,
}

#[feign(url = "http://127.0.0.1")]
impl Header {
    #[post]
    pub async fn helloWorld(&self) -> feignhttp::Result<String> {}
}

from feignhttp.

liyang-hg avatar liyang-hg commented on July 26, 2024

I saw this usage and I currently use it this way, but I prefer not to rely entirely on impl's struct. Suppose there are 2 methods under the Header. Only a few of their properties are public and the rest are different. If they are all put together So most of the book attributes for a certain method are redundant, so I hope #[header]#[query] can be as flexible as #[form]#[body]

for example:

#[derive(Feign)]
pub struct HttpClient {
    #[url_path("owner")]
    user: String,
    #[url_path]
    repo: String,
    #[param]
    accept: String,
}

#[derive(Feign)]
pub struct Header {
    #[serde(rename = "userAgent")]
    pub user_agent: String,
    
    pub access_token: String,
}

#[derive(Feign)]
pub struct Query {
    #[serde(rename = "query1")]
    pub query_1: String,
    
    pub query_2: String,
}

#[feign(url = "http://127.0.0.1")]
impl HttpClient {
    #[post]
    pub async fn post(&self, #[header] header: Header)) -> feignhttp::Result<String> {}

    #[get]
    pub async fn get(&self, #[query] query: Query)) -> feignhttp::Result<String> {}
}

from feignhttp.

dxx avatar dxx commented on July 26, 2024

This commit already supports that use structures in parameter of header and query.

Usage:

use serde::Serialize;


// Example for header.

#[derive(Serialize)]
pub struct Header {
    pub accept: &'static str,
    pub token: String,
}

#[get("https://httpbin.org/headers")]
async fn struct_headers(#[header] head: Header) -> feignhttp::Result<String> {}

// Example for query.

#[derive(Serialize)]
pub struct Query {
    pub id: i32,
    pub name: String
}

#[get("https://httpbin.org/anything")]
async fn anything_struct(#[query] q: Query) -> feignhttp::Result<String> {}

This is available in version 0.5.2.

from feignhttp.

Related Issues (7)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.