Conreg Feign
This crate provides procedural macros for creating Feign-like declarative HTTP clients.
Feign Client Macro
Used to create declarative HTTP clients similar to Java Feign. By annotating a trait with this macro, implementation code for HTTP requests is automatically generated, enabling RESTful communication between microservices.
Parameters
service_id: Required, the unique identifier of the service, used for service discovery and load balancing.base_path: Optional, the base path prefix that will be prepended to all request paths.url: Optional, directly specifies the base URL for requests; if set,service_idandbase_pathwill be ignored.
Example:
// Then, you can use the generated client like this:
let client = default;
let user = client.get_user.await?;
Http Method Macros
Supported HTTP Method Annotations
#[get]#[post]#[put]#[delete]#[patch]
Parameter Binding Methods
Path Parameters
Use {param_name} placeholders in the path. When a method parameter name matches the placeholder name, it is automatically bound.
Example:
async ;
Query Parameters
Use query = "{param}" to specify query parameter templates.
Example:
async ;
Form Parameters
Use form = "{param}" to specify form data, supporting application/x-www-form-urlencoded and multipart/form-data.
Example:
async ;
Body Parameter
Use body = "{param}" to specify the raw string body.
Example:
async ;
JSON Parameter
Use json = "{param}" to specify JSON data; it will be automatically serialized and Content-Type: application/json will be set.
Note: need serde_json
Example:
async
Header Parameter
Use headers("Key=Value", ...) or headers("Key={param}", ...) to specify request headers, supporting both static values and dynamic parameters.
Example:
async