{"id":15036673,"url":"https://github.com/openfeign/feign","last_synced_at":"2026-02-20T18:07:54.190Z","repository":{"id":9180216,"uuid":"10981994","full_name":"OpenFeign/feign","owner":"OpenFeign","description":"Feign makes writing java http clients easier","archived":false,"fork":false,"pushed_at":"2025-04-16T05:47:03.000Z","size":9788,"stargazers_count":9643,"open_issues_count":224,"forks_count":1942,"subscribers_count":398,"default_branch":"master","last_synced_at":"2025-04-16T22:41:32.859Z","etag":null,"topics":["http-client","interface","java","jax-rs","okhttp3","slf4j"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/OpenFeign.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"github":["velo"],"patreon":"velo132"}},"created_at":"2013-06-26T23:28:16.000Z","updated_at":"2025-04-15T19:00:41.000Z","dependencies_parsed_at":"2023-10-02T12:39:01.076Z","dependency_job_id":"6f23d3c9-33a1-44e1-a09e-5988762dc102","html_url":"https://github.com/OpenFeign/feign","commit_stats":{"total_commits":1857,"total_committers":304,"mean_commits":6.108552631578948,"dds":0.6763597199784599,"last_synced_commit":"2b954545e6c01dfc8a101f3f027c1a7a089e4ab5"},"previous_names":["netflix/feign"],"tags_count":148,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OpenFeign%2Ffeign","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OpenFeign%2Ffeign/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OpenFeign%2Ffeign/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OpenFeign%2Ffeign/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/OpenFeign","download_url":"https://codeload.github.com/OpenFeign/feign/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250528693,"owners_count":21445511,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["http-client","interface","java","jax-rs","okhttp3","slf4j"],"created_at":"2024-09-24T20:31:54.809Z","updated_at":"2025-12-17T02:52:16.957Z","avatar_url":"https://github.com/OpenFeign.png","language":"Java","readme":"# Feign simplifies the process of writing Java HTTP clients\n\n[![Join the chat at https://gitter.im/OpenFeign/feign](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/OpenFeign/feign?utm_source=badge\u0026utm_medium=badge\u0026utm_campaign=pr-badge\u0026utm_content=badge)\n[![CI](https://github.com/OpenFeign/feign/actions/workflows/build.yml/badge.svg?branch=master)](https://github.com/OpenFeign/feign/actions/workflows/build.yml)\n[![Maven Central](https://maven-badges.herokuapp.com/maven-central/io.github.openfeign/feign-core/badge.png)](https://search.maven.org/artifact/io.github.openfeign/feign-core/)\n\nFeign is a Java to HTTP client binder inspired by [Retrofit](https://github.com/square/retrofit), [JAXRS-2.0](https://jax-rs-spec.java.net/nonav/2.0/apidocs/index.html), and [WebSocket](http://www.oracle.com/technetwork/articles/java/jsr356-1937161.html).  Feign's first goal was reducing the complexity of binding [Denominator](https://github.com/Netflix/Denominator) uniformly to HTTP APIs regardless of [ReSTfulness](http://www.slideshare.net/adrianfcole/99problems).\n\n---\n### Why Feign and not X?\n\nFeign uses tools like Jersey and CXF to write Java clients for ReST or SOAP services. Furthermore, Feign allows you to write your own code on top of http libraries such as Apache HC. Feign connects your code to http APIs with minimal overhead and code via customizable decoders and error handling, which can be written to any text-based http API.\n\n### How does Feign work?\n\nFeign works by processing annotations into a templatized request. Arguments are applied to these templates in a straightforward fashion before output.  Although Feign is limited to supporting text-based APIs, it dramatically simplifies system aspects such as replaying requests. Furthermore, Feign makes it easy to unit test your conversions knowing this.\n\n### Java Version Compatibility\n\nFeign 10.x and above are built on Java 8 and should work on Java 9, 10, and 11.  For those that need JDK 6 compatibility, please use Feign 9.x\n\n## Feature overview\n\nThis is a map with current key features provided by feign:\n\n![MindMap overview](http://www.plantuml.com/plantuml/proxy?cache=no\u0026src=https://raw.githubusercontent.com/OpenFeign/feign/master/src/docs/overview-mindmap.iuml)\n\n# Roadmap\n## Feign 11 and beyond\nMaking _API_ clients easier\n\nShort Term - What we're working on now. ⏰\n---\n* Response Caching\n  * Support caching of api responses.  Allow for users to define under what conditions a response is eligible for caching and what type of caching mechanism should be used.\n  * Support in-memory caching and external cache implementations (EhCache, Google, Spring, etc...)\n* Complete URI Template expression support\n  * Support [level 1 through level 4](https://tools.ietf.org/html/rfc6570#section-1.2) URI template expressions.\n  * Use [URI Templates TCK](https://github.com/uri-templates/uritemplate-test) to verify compliance.\n* `Logger` API refactor\n  * Refactor the `Logger` API to adhere closer to frameworks like SLF4J providing a common mental model for logging within Feign.  This model will be used by Feign itself throughout and provide clearer direction on how the `Logger` will be used.\n* `Retry` API refactor\n  * Refactor the `Retry` API to support user-supplied conditions and better control over back-off policies. **This may result in non-backward-compatible breaking changes**\n\nMedium Term - What's up next. ⏲\n---\n* Async execution support via `CompletableFuture`\n  * Allow for `Future` chaining and executor management for the request/response lifecycle.  **Implementation will require non-backward-compatible breaking changes**.  However this feature is required before Reactive execution can be considered.\n* Reactive execution support via [Reactive Streams](https://www.reactive-streams.org/)\n  * For JDK 9+, consider a native implementation that uses `java.util.concurrent.Flow`.\n  * Support for [Project Reactor](https://projectreactor.io/) and [RxJava 2+](https://github.com/ReactiveX/RxJava) implementations on JDK 8.\n\nLong Term - The future ☁️\n---\n* Additional Circuit Breaker Support.\n  * Support additional Circuit Breaker implementations like [Resilience4J](https://resilience4j.readme.io/) and Spring Circuit Breaker\n\n---\n\n# Usage\n\nThe feign library is available from [Maven Central](https://central.sonatype.com/artifact/io.github.openfeign/feign-core).\n\n```xml\n\u003cdependency\u003e\n    \u003cgroupId\u003eio.github.openfeign\u003c/groupId\u003e\n    \u003cartifactId\u003efeign-core\u003c/artifactId\u003e\n    \u003cversion\u003e??feign.version??\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\n### Basics\n\nUsage typically looks like this, an adaptation of the [canonical Retrofit sample](https://github.com/square/retrofit/blob/master/samples/src/main/java/com/example/retrofit/SimpleService.java).\n\n```java\ninterface GitHub {\n  @RequestLine(\"GET /repos/{owner}/{repo}/contributors\")\n  List\u003cContributor\u003e contributors(@Param(\"owner\") String owner, @Param(\"repo\") String repo);\n\n  @RequestLine(\"POST /repos/{owner}/{repo}/issues\")\n  void createIssue(Issue issue, @Param(\"owner\") String owner, @Param(\"repo\") String repo);\n\n}\n\npublic static class Contributor {\n  String login;\n  int contributions;\n}\n\npublic static class Issue {\n  String title;\n  String body;\n  List\u003cString\u003e assignees;\n  int milestone;\n  List\u003cString\u003e labels;\n}\n\npublic class MyApp {\n  public static void main(String... args) {\n    GitHub github = Feign.builder()\n                         .decoder(new GsonDecoder())\n                         .target(GitHub.class, \"https://api.github.com\");\n\n    // Fetch and print a list of the contributors to this library.\n    List\u003cContributor\u003e contributors = github.contributors(\"OpenFeign\", \"feign\");\n    for (Contributor contributor : contributors) {\n      System.out.println(contributor.login + \" (\" + contributor.contributions + \")\");\n    }\n  }\n}\n```\n\n### Interface Annotations\n\nFeign annotations define the `Contract` between the interface and how the underlying client\nshould work.  Feign's default contract defines the following annotations:\n\n| Annotation     | Interface Target | Usage |\n|----------------|------------------|-------|\n| `@RequestLine` | Method           | Defines the `HttpMethod` and `UriTemplate` for request.  `Expressions`, values wrapped in curly-braces `{expression}` are resolved using their corresponding `@Param` annotated parameters. |\n| `@Param`       | Parameter        | Defines a template variable, whose value will be used to resolve the corresponding template `Expression`, by name provided as annotation value. If value is missing it will try to get the name from bytecode method parameter name (if the code was compiled with `-parameters` flag). |\n| `@Headers`     | Method, Type     | Defines a `HeaderTemplate`; a variation on a `UriTemplate`.  that uses `@Param` annotated values to resolve the corresponding `Expressions`.  When used on a `Type`, the template will be applied to every request.  When used on a `Method`, the template will apply only to the annotated method. |\n| `@QueryMap`    | Parameter        | Defines a `Map` of name-value pairs, or POJO, to expand into a query string. |\n| `@HeaderMap`   | Parameter        | Defines a `Map` of name-value pairs, to expand into `Http Headers` |\n| `@Body`        | Method           | Defines a `Template`, similar to a `UriTemplate` and `HeaderTemplate`, that uses `@Param` annotated values to resolve the corresponding `Expressions`.|\n\n\n\u003e **Overriding the Request Line**\n\u003e\n\u003e If there is a need to target a request to a different host then the one supplied when the Feign client was created, or\n\u003e you want to supply a target host for each request, include a `java.net.URI` parameter and Feign will use that value\n\u003e as the request target.\n\u003e\n\u003e ```java\n\u003e @RequestLine(\"POST /repos/{owner}/{repo}/issues\")\n\u003e void createIssue(URI host, Issue issue, @Param(\"owner\") String owner, @Param(\"repo\") String repo);\n\u003e ```\n\u003e\n\n### Templates and Expressions\n\nFeign `Expressions` represent Simple String Expressions (Level 1) as defined by [URI Template - RFC 6570](https://tools.ietf.org/html/rfc6570).  `Expressions` are expanded using\ntheir corresponding `Param` annotated method parameters.\n\n*Example*\n\n```java\npublic interface GitHub {\n\n  @RequestLine(\"GET /repos/{owner}/{repo}/contributors\")\n  List\u003cContributor\u003e contributors(@Param(\"owner\") String owner, @Param(\"repo\") String repository);\n\n  class Contributor {\n    String login;\n    int contributions;\n  }\n}\n\npublic class MyApp {\n  public static void main(String[] args) {\n    GitHub github = Feign.builder()\n                         .decoder(new GsonDecoder())\n                         .target(GitHub.class, \"https://api.github.com\");\n\n    /* The owner and repository parameters will be used to expand the owner and repo expressions\n     * defined in the RequestLine.\n     *\n     * the resulting uri will be https://api.github.com/repos/OpenFeign/feign/contributors\n     */\n    github.contributors(\"OpenFeign\", \"feign\");\n  }\n}\n```\n\nExpressions must be enclosed in curly braces `{}` and may contain regular expression patterns, separated by a colon `:`  to restrict\nresolved values.  *Example* `owner` must be alphabetic. `{owner:[a-zA-Z]*}`\n\n#### Request Parameter Expansion\n\n`RequestLine` and `QueryMap` templates follow the [URI Template - RFC 6570](https://tools.ietf.org/html/rfc6570) specification for Level 1 templates, which specifies the following:\n\n* Unresolved expressions are omitted.\n* All literals and variable values are pct-encoded, if not already encoded or marked `encoded` via a `@Param` annotation.\n\nWe also have limited support for Level 3, Path Style Expressions, with the following restrictions:\n\n* Maps and Lists are expanded by default.\n* Only Single variable templates are supported.\n\n*Examples:*\n\n```\n{;who}             ;who=fred\n{;half}            ;half=50%25\n{;empty}           ;empty\n{;list}            ;list=red;list=green;list=blue\n{;map}             ;semi=%3B;dot=.;comma=%2C\n```\n\n```java\npublic interface MatrixService {\n\n  @RequestLine(\"GET /repos{;owners}\")\n  List\u003cContributor\u003e contributors(@Param(\"owners\") List\u003cString\u003e owners);\n\n  class Contributor {\n    String login;\n    int contributions;\n  }\n}\n```\n\nIf `owners` in the above example is defined as `Matt, Jeff, Susan`, the uri will expand to `/repos;owners=Matt;owners=Jeff;owners=Susan` \n\nFor more information see [RFC 6570, Section 3.2.7](https://datatracker.ietf.org/doc/html/rfc6570#section-3.2.7)\n\n#### Undefined vs. Empty Values ####\n\nUndefined expressions are expressions where the value for the expression is an explicit `null` or no value is provided.\nPer [URI Template - RFC 6570](https://tools.ietf.org/html/rfc6570), it is possible to provide an empty value\nfor an expression.  When Feign resolves an expression, it first determines if the value is defined, if it is then\nthe query parameter will remain.  If the expression is undefined, the query parameter is removed.  See below\nfor a complete breakdown.\n\n*Empty String*\n```java\npublic void test() {\n   Map\u003cString, Object\u003e parameters = new LinkedHashMap\u003c\u003e();\n   parameters.put(\"param\", \"\");\n   this.demoClient.test(parameters);\n}\n```\nResult\n```\nhttp://localhost:8080/test?param=\n```\n\n*Missing*\n```java\npublic void test() {\n   Map\u003cString, Object\u003e parameters = new LinkedHashMap\u003c\u003e();\n   this.demoClient.test(parameters);\n}\n```\nResult\n```\nhttp://localhost:8080/test\n```\n\n*Undefined*\n```java\npublic void test() {\n   Map\u003cString, Object\u003e parameters = new LinkedHashMap\u003c\u003e();\n   parameters.put(\"param\", null);\n   this.demoClient.test(parameters);\n}\n```\nResult\n```\nhttp://localhost:8080/test\n```\n\nSee [Advanced Usage](#advanced-usage) for more examples.\n\n\u003e **What about slashes? `/`**\n\u003e\n\u003e @RequestLine templates do not encode slash `/` characters by default.  To change this behavior, set the `decodeSlash` property on the `@RequestLine` to `false`.\n\n\u003e **What about plus? `+`**\n\u003e\n\u003e Per the URI specification, a `+` sign is allowed in both the path and query segments of a URI, however, handling of\n\u003e the symbol on the query can be inconsistent.  In some legacy systems, the `+` is equivalent to the a space.  Feign takes the approach of modern systems, where a\n\u003e `+` symbol should not represent a space and is explicitly encoded as `%2B` when found on a query string.\n\u003e\n\u003e If you wish to use `+` as a space, then use the literal ` ` character or encode the value directly as `%20`\n\n##### Custom Expansion\n\nThe `@Param` annotation has an optional property `expander` allowing for complete control over the individual parameter's expansion.\nThe `expander` property must reference a class that implements the `Expander` interface:\n\n```java\npublic interface Expander {\n    String expand(Object value);\n}\n```\nThe result of this method adheres to the same rules stated above.  If the result is `null` or an empty string,\nthe value is omitted.  If the value is not pct-encoded, it will be.  See [Custom @Param Expansion](#custom-param-expansion) for more examples.\n\n#### Request Headers Expansion\n\n`Headers` and `HeaderMap` templates follow the same rules as [Request Parameter Expansion](#request-parameter-expansion)\nwith the following alterations:\n\n* Unresolved expressions are omitted.  If the result is an empty header value, the entire header is removed.\n* No pct-encoding is performed.\n\nSee [Headers](#headers) for examples.\n\n\u003e **A Note on `@Param` parameters and their names**:\n\u003e\n\u003e All expressions with the same name, regardless of their position on the `@RequestLine`, `@QueryMap`, `@BodyTemplate`, or `@Headers` will resolve to the same value.\n\u003e In the following example, the value of `contentType`, will be used to resolve both the header and path expression:\n\u003e\n\u003e ```java\n\u003e public interface ContentService {\n\u003e   @RequestLine(\"GET /api/documents/{contentType}\")\n\u003e   @Headers(\"Accept: {contentType}\")\n\u003e   String getDocumentByType(@Param(\"contentType\") String type);\n\u003e }\n\u003e```\n\u003e\n\u003e Keep this in mind when designing your interfaces.\n\n#### Request Body Expansion\n\n`Body` templates follow the same rules as [Request Parameter Expansion](#request-parameter-expansion)\nwith the following alterations:\n\n* Unresolved expressions are omitted.\n* Expanded value will **not** be passed through an `Encoder` before being placed on the request body.\n* A `Content-Type` header must be specified.  See [Body Templates](#body-templates) for examples.\n\n---\n### Customization\n\nFeign has several aspects that can be customized.  \nFor simple cases, you can use `Feign.builder()` to construct an API interface with your custom components.\u003cbr\u003e\nFor request setting, you can use `options(Request.Options options)` on `target()` to set connectTimeout, connectTimeoutUnit, readTimeout, readTimeoutUnit, followRedirects.\u003cbr\u003e\nFor example:\n\n```java\ninterface Bank {\n  @RequestLine(\"POST /account/{id}\")\n  Account getAccountInfo(@Param(\"id\") String id);\n}\n\npublic class BankService {\n  public static void main(String[] args) {\n    Bank bank = Feign.builder()\n        .decoder(new AccountDecoder())\n        .options(new Request.Options(10, TimeUnit.SECONDS, 60, TimeUnit.SECONDS, true))\n        .target(Bank.class, \"https://api.examplebank.com\");\n  }\n}\n```\n\n### Multiple Interfaces\nFeign can produce multiple api interfaces.  These are defined as `Target\u003cT\u003e` (default `HardCodedTarget\u003cT\u003e`), which allow for dynamic discovery and decoration of requests prior to execution.\n\nFor example, the following pattern might decorate each request with the current url and auth token from the identity service.\n\n```java\npublic class CloudService {\n  public static void main(String[] args) {\n    CloudDNS cloudDNS = Feign.builder()\n      .target(new CloudIdentityTarget\u003cCloudDNS\u003e(user, apiKey));\n  }\n\n  class CloudIdentityTarget extends Target\u003cCloudDNS\u003e {\n    /* implementation of a Target */\n  }\n}\n```\n\n### Examples\nFeign includes example [GitHub](./example-github) and [Wikipedia](./example-wikipedia) clients. The denominator project can also be scraped for Feign in practice. Particularly, look at its [example daemon](https://github.com/Netflix/denominator/tree/master/example-daemon).\n\n---\n### Integrations\nFeign intends to work well with other Open Source tools.  Modules are welcome to integrate with your favorite projects!\n\n### Encoder/Decoder\n\n#### Gson\n[Gson](./gson) includes an encoder and decoder you can use with a JSON API.\n\nAdd `GsonEncoder` and/or `GsonDecoder` to your `Feign.Builder` like so:\n\n```java\npublic class Example {\n  public static void main(String[] args) {\n    GsonCodec codec = new GsonCodec();\n    GitHub github = Feign.builder()\n                         .encoder(new GsonEncoder())\n                         .decoder(new GsonDecoder())\n                         .target(GitHub.class, \"https://api.github.com\");\n  }\n}\n```\n\n#### Jackson\n[Jackson](./jackson) includes an encoder and decoder you can use with a JSON API.\n\nAdd `JacksonEncoder` and/or `JacksonDecoder` to your `Feign.Builder` like so:\n\n```java\npublic class Example {\n  public static void main(String[] args) {\n      GitHub github = Feign.builder()\n                     .encoder(new JacksonEncoder())\n                     .decoder(new JacksonDecoder())\n                     .target(GitHub.class, \"https://api.github.com\");\n  }\n}\n```\n\nFor the lighter weight Jackson Jr, use `JacksonJrEncoder` and `JacksonJrDecoder` from\nthe [Jackson Jr Module](./jackson-jr).\n\n#### Moshi\n[Moshi](./moshi) includes an encoder and decoder you can use with a JSON API.\nAdd `MoshiEncoder` and/or `MoshiDecoder` to your `Feign.Builder` like so:\n\n```java\nGitHub github = Feign.builder()\n                     .encoder(new MoshiEncoder())\n                     .decoder(new MoshiDecoder())\n                     .target(GitHub.class, \"https://api.github.com\");\n```\n\n#### Sax\n[SaxDecoder](./sax) allows you to decode XML in a way that is compatible with normal JVM and also Android environments.\n\nHere's an example of how to configure Sax response parsing:\n```java\npublic class Example {\n  public static void main(String[] args) {\n      Api api = Feign.builder()\n         .decoder(SAXDecoder.builder()\n                            .registerContentHandler(UserIdHandler.class)\n                            .build())\n         .target(Api.class, \"https://apihost\");\n    }\n}\n```\n\n#### JAXB\n[JAXB](./jaxb) includes an encoder and decoder you can use with an XML API.\n\nAdd `JAXBEncoder` and/or `JAXBDecoder` to your `Feign.Builder` like so:\n\n```java\npublic class Example {\n  public static void main(String[] args) {\n    Api api = Feign.builder()\n             .encoder(new JAXBEncoder())\n             .decoder(new JAXBDecoder())\n             .target(Api.class, \"https://apihost\");\n  }\n}\n```\n\n#### SOAP\n[SOAP](./soap) includes an encoder and decoder you can use with an XML API.\n\n\nThis module adds support for encoding and decoding SOAP Body objects via JAXB and SOAPMessage. It also provides SOAPFault decoding capabilities by wrapping them into the original `javax.xml.ws.soap.SOAPFaultException`, so that you'll only need to catch `SOAPFaultException` in order to handle SOAPFault.\n\nAdd `SOAPEncoder` and/or `SOAPDecoder` to your `Feign.Builder` like so:\n\n```java\npublic class Example {\n  public static void main(String[] args) {\n    Api api = Feign.builder()\n\t     .encoder(new SOAPEncoder(jaxbFactory))\n\t     .decoder(new SOAPDecoder(jaxbFactory))\n\t     .errorDecoder(new SOAPErrorDecoder())\n\t     .target(MyApi.class, \"http://api\");\n  }\n}\n```\n\nNB: you may also need to add `SOAPErrorDecoder` if SOAP Faults are returned in response with error http codes (4xx, 5xx, ...)\n\n#### Fastjson2 \n\n[fastjson2](./fastjson2) includes an encoder and decoder you can use with a JSON API.\n\nAdd `Fastjson2Encoder` and/or `Fastjson2Decoder` to your `Feign.Builder` like so:\n\n```java\npublic class Example {\n  public static void main(String[] args) {\n      GitHub github = Feign.builder()\n                     .encoder(new Fastjson2Encoder())\n                     .decoder(new Fastjson2Decoder())\n                     .target(GitHub.class, \"https://api.github.com\");\n  }\n}\n```\n\n### Contract\n\n#### JAX-RS\n[JAXRSContract](./jaxrs) overrides annotation processing to instead use standard ones supplied by the JAX-RS specification.  This is currently targeted at the 1.1 spec.\n\nHere's the example above re-written to use JAX-RS:\n```java\ninterface GitHub {\n  @GET @Path(\"/repos/{owner}/{repo}/contributors\")\n  List\u003cContributor\u003e contributors(@PathParam(\"owner\") String owner, @PathParam(\"repo\") String repo);\n}\n\npublic class Example {\n  public static void main(String[] args) {\n    GitHub github = Feign.builder()\n                       .contract(new JAXRSContract())\n                       .target(GitHub.class, \"https://api.github.com\");\n  }\n}\n```\n\n### Client\n\n#### OkHttp\n[OkHttpClient](./okhttp) directs Feign's http requests to [OkHttp](http://square.github.io/okhttp/), which enables SPDY and better network control.\n\nTo use OkHttp with Feign, add the OkHttp module to your classpath. Then, configure Feign to use the OkHttpClient:\n\n```java\npublic class Example {\n  public static void main(String[] args) {\n    GitHub github = Feign.builder()\n                     .client(new OkHttpClient())\n                     .target(GitHub.class, \"https://api.github.com\");\n  }\n}\n```\n\n#### Ribbon\n[RibbonClient](./ribbon) overrides URL resolution of Feign's client, adding smart routing and resiliency capabilities provided by [Ribbon](https://github.com/Netflix/ribbon).\n\nIntegration requires you to pass your ribbon client name as the host part of the url, for example `myAppProd`.\n```java\npublic class Example {\n  public static void main(String[] args) {\n    MyService api = Feign.builder()\n          .client(RibbonClient.create())\n          .target(MyService.class, \"https://myAppProd\");\n  }\n}\n```\n\n#### Java 11 Http2\n[Http2Client](./java11) directs Feign's http requests to Java11 [New HTTP/2 Client](https://openjdk.java.net/jeps/321) that implements HTTP/2.\n\nTo use New HTTP/2 Client with Feign, use Java SDK 11. Then, configure Feign to use the Http2Client:\n\n```java\nGitHub github = Feign.builder()\n                     .client(new Http2Client())\n                     .target(GitHub.class, \"https://api.github.com\");\n```\n\n### Breaker\n\n#### Hystrix\n[HystrixFeign](./hystrix) configures circuit breaker support provided by [Hystrix](https://github.com/Netflix/Hystrix).\n\nTo use Hystrix with Feign, add the Hystrix module to your classpath. Then use the `HystrixFeign` builder:\n\n```java\npublic class Example {\n  public static void main(String[] args) {\n    MyService api = HystrixFeign.builder().target(MyService.class, \"https://myAppProd\");\n  }\n}\n```\n\n### Logger\n\n#### SLF4J\n[SLF4JModule](./slf4j) allows directing Feign's logging to [SLF4J](http://www.slf4j.org/), allowing you to easily use a logging backend of your choice (Logback, Log4J, etc.)\n\nTo use SLF4J with Feign, add both the SLF4J module and an SLF4J binding of your choice to your classpath.  Then, configure Feign to use the Slf4jLogger:\n\n```java\npublic class Example {\n  public static void main(String[] args) {\n    GitHub github = Feign.builder()\n                     .logger(new Slf4jLogger())\n                     .logLevel(Level.FULL)\n                     .target(GitHub.class, \"https://api.github.com\");\n  }\n}\n```\n\n### Decoders\n`Feign.builder()` allows you to specify additional configuration such as how to decode a response.\n\nIf any methods in your interface return types besides `Response`, `String`, `byte[]` or `void`, you'll need to configure a non-default `Decoder`.\n\nHere's how to configure JSON decoding (using the `feign-gson` extension):\n\n```java\npublic class Example {\n  public static void main(String[] args) {\n    GitHub github = Feign.builder()\n                     .decoder(new GsonDecoder())\n                     .target(GitHub.class, \"https://api.github.com\");\n  }\n}\n```\n\nIf you need to pre-process the response before give it to the Decoder, you can use the `mapAndDecode` builder method.\nAn example use case is dealing with an API that only serves jsonp, you will maybe need to unwrap the jsonp before\nsend it to the Json decoder of your choice:\n\n```java\npublic class Example {\n  public static void main(String[] args) {\n    JsonpApi jsonpApi = Feign.builder()\n                         .mapAndDecode((response, type) -\u003e jsopUnwrap(response, type), new GsonDecoder())\n                         .target(JsonpApi.class, \"https://some-jsonp-api.com\");\n  }\n}\n```\n\nIf any methods in your interface return type `Stream`, you'll need to configure a `StreamDecoder`.\n\nHere's how to configure Stream decoder without delegate decoder:\n\n```java\npublic class Example {\n  public static void main(String[] args) {\n    GitHub github = Feign.builder()\n            .decoder(StreamDecoder.create((r, t) -\u003e {\n              BufferedReader bufferedReader = new BufferedReader(r.body().asReader(UTF_8));\n              return bufferedReader.lines().iterator();\n            }))\n            .target(GitHub.class, \"https://api.github.com\");\n  }\n}\n``` \n\nHere's how to configure Stream decoder with delegate decoder:\n\n```java\n\npublic class Example {\n  public static void main(String[] args) {\n    GitHub github = Feign.builder()\n            .decoder(StreamDecoder.create((r, t) -\u003e {\n              BufferedReader bufferedReader = new BufferedReader(r.body().asReader(UTF_8));\n              return bufferedReader.lines().iterator();\n            }, (r, t) -\u003e \"this is delegate decoder\"))\n            .target(GitHub.class, \"https://api.github.com\");\n  }\n}\n```\n\n### Encoders\nThe simplest way to send a request body to a server is to define a `POST` method that has a `String` or `byte[]` parameter without any annotations on it. You will likely need to add a `Content-Type` header.\n\n```java\ninterface LoginClient {\n  @RequestLine(\"POST /\")\n  @Headers(\"Content-Type: application/json\")\n  void login(String content);\n}\n\npublic class Example {\n  public static void main(String[] args) {\n    client.login(\"{\\\"user_name\\\": \\\"denominator\\\", \\\"password\\\": \\\"secret\\\"}\");\n  }\n}\n```\n\nBy configuring an `Encoder`, you can send a type-safe request body. Here's an example using the `feign-gson` extension:\n\n```java\nstatic class Credentials {\n  final String user_name;\n  final String password;\n\n  Credentials(String user_name, String password) {\n    this.user_name = user_name;\n    this.password = password;\n  }\n}\n\ninterface LoginClient {\n  @RequestLine(\"POST /\")\n  void login(Credentials creds);\n}\n\npublic class Example {\n  public static void main(String[] args) {\n    LoginClient client = Feign.builder()\n                              .encoder(new GsonEncoder())\n                              .target(LoginClient.class, \"https://foo.com\");\n\n    client.login(new Credentials(\"denominator\", \"secret\"));\n  }\n}\n```\n\n### @Body templates\nThe `@Body` annotation indicates a template to expand using parameters annotated with `@Param`. You will likely need to add a `Content-Type` header.\n\n```java\ninterface LoginClient {\n\n  @RequestLine(\"POST /\")\n  @Headers(\"Content-Type: application/xml\")\n  @Body(\"\u003clogin \\\"user_name\\\"=\\\"{user_name}\\\" \\\"password\\\"=\\\"{password}\\\"/\u003e\")\n  void xml(@Param(\"user_name\") String user, @Param(\"password\") String password);\n\n  @RequestLine(\"POST /\")\n  @Headers(\"Content-Type: application/json\")\n  // json curly braces must be escaped!\n  @Body(\"%7B\\\"user_name\\\": \\\"{user_name}\\\", \\\"password\\\": \\\"{password}\\\"%7D\")\n  void json(@Param(\"user_name\") String user, @Param(\"password\") String password);\n}\n\npublic class Example {\n  public static void main(String[] args) {\n    client.xml(\"denominator\", \"secret\"); // \u003clogin \"user_name\"=\"denominator\" \"password\"=\"secret\"/\u003e\n    client.json(\"denominator\", \"secret\"); // {\"user_name\": \"denominator\", \"password\": \"secret\"}\n  }\n}\n```\n\n### Headers\nFeign supports settings headers on requests either as part of the api or as part of the client\ndepending on the use case.\n\n#### Set headers using apis\nIn cases where specific interfaces or calls should always have certain header values set, it\nmakes sense to define headers as part of the api.\n\nStatic headers can be set on an api interface or method using the `@Headers` annotation.\n\n```java\n@Headers(\"Accept: application/json\")\ninterface BaseApi\u003cV\u003e {\n  @Headers(\"Content-Type: application/json\")\n  @RequestLine(\"PUT /api/{key}\")\n  void put(@Param(\"key\") String key, V value);\n}\n```\n\nMethods can specify dynamic content for static headers using variable expansion in `@Headers`.\n\n```java\npublic interface Api {\n   @RequestLine(\"POST /\")\n   @Headers(\"X-Ping: {token}\")\n   void post(@Param(\"token\") String token);\n}\n```\n\nIn cases where both the header field keys and values are dynamic and the range of possible keys cannot\nbe known ahead of time and may vary between different method calls in the same api/client (e.g. custom\nmetadata header fields such as \"x-amz-meta-\\*\" or \"x-goog-meta-\\*\"), a Map parameter can be annotated\nwith `HeaderMap` to construct a query that uses the contents of the map as its header parameters.\n\n```java\npublic interface Api {\n   @RequestLine(\"POST /\")\n   void post(@HeaderMap Map\u003cString, Object\u003e headerMap);\n}\n```\n\nThese approaches specify header entries as part of the api and do not require any customizations\nwhen building the Feign client.\n\n#### Setting headers per target\nTo customize headers for each request method on a Target, a RequestInterceptor can be used. RequestInterceptors can be\nshared across Target instances and are expected to be thread-safe. RequestInterceptors are applied to all request\nmethods on a Target.\n\nIf you need per method customization, a custom Target is required, as the a RequestInterceptor does not have access to\nthe current method metadata.\n\nFor an example of setting headers using a `RequestInterceptor`, see the `Request Interceptors` section.\n\nHeaders can be set as part of a custom `Target`.\n\n```java\n  static class DynamicAuthTokenTarget\u003cT\u003e implements Target\u003cT\u003e {\n    public DynamicAuthTokenTarget(Class\u003cT\u003e clazz,\n                                  UrlAndTokenProvider provider,\n                                  ThreadLocal\u003cString\u003e requestIdProvider);\n\n    @Override\n    public Request apply(RequestTemplate input) {\n      TokenIdAndPublicURL urlAndToken = provider.get();\n      if (input.url().indexOf(\"http\") != 0) {\n        input.insert(0, urlAndToken.publicURL);\n      }\n      input.header(\"X-Auth-Token\", urlAndToken.tokenId);\n      input.header(\"X-Request-ID\", requestIdProvider.get());\n\n      return input.request();\n    }\n  }\n\n  public class Example {\n    public static void main(String[] args) {\n      Bank bank = Feign.builder()\n              .target(new DynamicAuthTokenTarget(Bank.class, provider, requestIdProvider));\n    }\n  }\n```\n\nThese approaches depend on the custom `RequestInterceptor` or `Target` being set on the Feign\nclient when it is built and can be used as a way to set headers on all api calls on a per-client\nbasis. This can be useful for doing things such as setting an authentication token in the header\nof all api requests on a per-client basis. The methods are run when the api call is made on the\nthread that invokes the api call, which allows the headers to be set dynamically at call time and\nin a context-specific manner -- for example, thread-local storage can be used to set different\nheader values depending on the invoking thread, which can be useful for things such as setting\nthread-specific trace identifiers for requests.\n\n#### Set zero Content-Length Header\n\nTo specify `Content-Length: 0` header when making a request with empty body, system property `sun.net.http.allowRestrictedHeaders` should be set to `true`\n\nIf not, the `Content-Length` header will not be added.\n\n### Advanced usage\n\n#### Base Apis\nIn many cases, apis for a service follow the same conventions. Feign supports this pattern via single-inheritance interfaces.\n\nConsider the example:\n```java\ninterface BaseAPI {\n  @RequestLine(\"GET /health\")\n  String health();\n\n  @RequestLine(\"GET /all\")\n  List\u003cEntity\u003e all();\n}\n```\n\nYou can define and target a specific api, inheriting the base methods.\n```java\ninterface CustomAPI extends BaseAPI {\n  @RequestLine(\"GET /custom\")\n  String custom();\n}\n```\n\nIn many cases, resource representations are also consistent. For this reason, type parameters are supported on the base api interface.\n\n```java\n@Headers(\"Accept: application/json\")\ninterface BaseApi\u003cV\u003e {\n\n  @RequestLine(\"GET /api/{key}\")\n  V get(@Param(\"key\") String key);\n\n  @RequestLine(\"GET /api\")\n  List\u003cV\u003e list();\n\n  @Headers(\"Content-Type: application/json\")\n  @RequestLine(\"PUT /api/{key}\")\n  void put(@Param(\"key\") String key, V value);\n}\n\ninterface FooApi extends BaseApi\u003cFoo\u003e { }\n\ninterface BarApi extends BaseApi\u003cBar\u003e { }\n```\n\n#### Logging\nYou can log the http messages going to and from the target by setting up a `Logger`.  Here's the easiest way to do that:\n```java\npublic class Example {\n  public static void main(String[] args) {\n    GitHub github = Feign.builder()\n                     .decoder(new GsonDecoder())\n                     .logger(new Logger.JavaLogger(\"GitHub.Logger\").appendToFile(\"logs/http.log\"))\n                     .logLevel(Logger.Level.FULL)\n                     .target(GitHub.class, \"https://api.github.com\");\n  }\n}\n```\n\n\u003e **A Note on JavaLogger**:\n\u003e Avoid using of default ```JavaLogger()``` constructor - it was marked as deprecated and will be removed soon.\n\nThe SLF4JLogger (see above) may also be of interest.\n\nTo filter out sensitive information like authorization or tokens\noverride methods `shouldLogRequestHeader` or `shouldLogResponseHeader`.\n\n#### Request Interceptors\nWhen you need to change all requests, regardless of their target, you'll want to configure a `RequestInterceptor`.\nFor example, if you are acting as an intermediary, you might want to propagate the `X-Forwarded-For` header.\n\n```java\nstatic class ForwardedForInterceptor implements RequestInterceptor {\n  @Override public void apply(RequestTemplate template) {\n    template.header(\"X-Forwarded-For\", \"origin.host.com\");\n  }\n}\n\npublic class Example {\n  public static void main(String[] args) {\n    Bank bank = Feign.builder()\n                 .decoder(accountDecoder)\n                 .requestInterceptor(new ForwardedForInterceptor())\n                 .target(Bank.class, \"https://api.examplebank.com\");\n  }\n}\n```\n\nAnother common example of an interceptor would be authentication, such as using the built-in `BasicAuthRequestInterceptor`.\n\n```java\npublic class Example {\n  public static void main(String[] args) {\n    Bank bank = Feign.builder()\n                 .decoder(accountDecoder)\n                 .requestInterceptor(new BasicAuthRequestInterceptor(username, password))\n                 .target(Bank.class, \"https://api.examplebank.com\");\n  }\n}\n```\n\n#### Custom @Param Expansion\nParameters annotated with `Param` expand based on their `toString`. By\nspecifying a custom `Param.Expander`, users can control this behavior,\nfor example formatting dates.\n\n```java\npublic interface Api {\n  @RequestLine(\"GET /?since={date}\") Result list(@Param(value = \"date\", expander = DateToMillis.class) Date date);\n}\n```\n\n#### Dynamic Query Parameters\nA Map parameter can be annotated with `QueryMap` to construct a query that uses the contents of the map as its query parameters.\n\n```java\npublic interface Api {\n  @RequestLine(\"GET /find\")\n  V find(@QueryMap Map\u003cString, Object\u003e queryMap);\n}\n```\n\nThis may also be used to generate the query parameters from a POJO object using a `QueryMapEncoder`.\n\n```java\npublic interface Api {\n  @RequestLine(\"GET /find\")\n  V find(@QueryMap CustomPojo customPojo);\n}\n```\n\nWhen used in this manner, without specifying a custom `QueryMapEncoder`, the query map will be generated using member variable names as query parameter names. You can annotate a specific field of `CustomPojo` with the `@Param` annotation to specify a different name to the query parameter. The following POJO will generate query params of \"/find?name={name}\u0026number={number}\u0026region_id={regionId}\" (order of included query parameters not guaranteed, and as usual, if any value is null, it will be left out).\n\n```java\npublic class CustomPojo {\n  private final String name;\n  private final int number;\n  @Param(\"region_id\")\n  private final String regionId;\n\n  public CustomPojo (String name, int number, String regionId) {\n    this.name = name;\n    this.number = number;\n    this.regionId = regionId;\n  }\n}\n```\n\nTo setup a custom `QueryMapEncoder`:\n\n```java\npublic class Example {\n  public static void main(String[] args) {\n    MyApi myApi = Feign.builder()\n                 .queryMapEncoder(new MyCustomQueryMapEncoder())\n                 .target(MyApi.class, \"https://api.hostname.com\");\n  }\n}\n```\n\nWhen annotating objects with @QueryMap, the default encoder uses reflection to inspect provided objects Fields to expand the objects values into a query string. If you prefer that the query string be built using getter and setter methods, as defined in the Java Beans API, please use the BeanQueryMapEncoder\n\n```java\npublic class Example {\n  public static void main(String[] args) {\n    MyApi myApi = Feign.builder()\n                 .queryMapEncoder(new BeanQueryMapEncoder())\n                 .target(MyApi.class, \"https://api.hostname.com\");\n  }\n}\n```\n\n### Error Handling\nIf you need more control over handling unexpected responses, Feign instances can\nregister a custom `ErrorDecoder` via the builder.\n\n```java\npublic class Example {\n  public static void main(String[] args) {\n    MyApi myApi = Feign.builder()\n                 .errorDecoder(new MyErrorDecoder())\n                 .target(MyApi.class, \"https://api.hostname.com\");\n  }\n}\n```\n\nAll responses that result in an HTTP status not in the 2xx range will trigger the `ErrorDecoder`'s `decode` method, allowing\nyou to handle the response, wrap the failure into a custom exception or perform any additional processing.\nIf you want to retry the request again, throw a `RetryableException`.  This will invoke the registered\n`Retryer`.\n\n### Retry\nFeign, by default, will automatically retry `IOException`s, regardless of HTTP method, treating them as transient network\nrelated exceptions, and any `RetryableException` thrown from an `ErrorDecoder`.  To customize this\nbehavior, register a custom `Retryer` instance via the builder.\n\nThe following example shows how to refresh token and retry with `ErrorDecoder` and `Retryer` when received a 401 response.\n\n```java\npublic class Example {\n    public static void main(String[] args) {\n        var github = Feign.builder()\n                .decoder(new GsonDecoder())\n                .retryer(new MyRetryer(100, 3))\n                .errorDecoder(new MyErrorDecoder())\n                .target(Github.class, \"https://api.github.com\");\n\n        var contributors = github.contributors(\"foo\", \"bar\", \"invalid_token\");\n        for (var contributor : contributors) {\n            System.out.println(contributor.login + \" \" + contributor.contributions);\n        }\n    }\n\n    static class MyErrorDecoder implements ErrorDecoder {\n\n        private final ErrorDecoder defaultErrorDecoder = new Default();\n\n        @Override\n        public Exception decode(String methodKey, Response response) {\n            // wrapper 401 to RetryableException in order to retry\n            if (response.status() == 401) {\n                return new RetryableException(response.status(), response.reason(), response.request().httpMethod(), null, response.request());\n            }\n            return defaultErrorDecoder.decode(methodKey, response);\n        }\n    }\n\n    static class MyRetryer implements Retryer {\n\n        private final long period;\n        private final int maxAttempts;\n        private int attempt = 1;\n\n        public MyRetryer(long period, int maxAttempts) {\n            this.period = period;\n            this.maxAttempts = maxAttempts;\n        }\n\n        @Override\n        public void continueOrPropagate(RetryableException e) {\n            if (++attempt \u003e maxAttempts) {\n                throw e;\n            }\n            if (e.status() == 401) {\n                // remove Authorization first, otherwise Feign will add a new Authorization header\n                // cause github responses a 400 bad request\n                e.request().requestTemplate().removeHeader(\"Authorization\");\n                e.request().requestTemplate().header(\"Authorization\", \"Bearer \" + getNewToken());\n                try {\n                    Thread.sleep(period);\n                } catch (InterruptedException ex) {\n                    throw e;\n                }\n            } else {\n                throw e;\n            }\n        }\n\n        // Access an external api to obtain new token\n        // In this example, we can simply return a fixed token to demonstrate how Retryer works\n        private String getNewToken() {\n            return \"newToken\";\n        }\n\n        @Override\n        public Retryer clone() {\n            return new MyRetryer(period, maxAttempts);\n        }\n}\n```\n\n`Retryer`s are responsible for determining if a retry should occur by returning either a `true` or\n`false` from the method `continueOrPropagate(RetryableException e);`  A `Retryer` instance will be\ncreated for each `Client` execution, allowing you to maintain state bewteen each request if desired.\n\nIf the retry is determined to be unsuccessful, the last `RetryException` will be thrown.  To throw the original\ncause that led to the unsuccessful retry, build your Feign client with the `exceptionPropagationPolicy()` option.\n\n#### Response Interceptor\nIf you need to treat what would otherwise be an error as a success and return a result rather than throw an exception then you may use a `ResponseInterceptor`.\n\nAs an example Feign includes a simple `RedirectionInterceptor` that can be used to extract the location header from redirection responses.\n```java\npublic interface Api {\n  // returns a 302 response\n  @RequestLine(\"GET /location\")\n  String location();\n}\n\npublic class MyApp {\n  public static void main(String[] args) {\n    // Configure the HTTP client to ignore redirection\n    Api api = Feign.builder()\n                   .options(new Options(10, TimeUnit.SECONDS, 60, TimeUnit.SECONDS, false))\n                   .responseInterceptor(new RedirectionInterceptor())\n                   .target(Api.class, \"https://redirect.example.com\");\n  }\n}\n```\n\n### Metrics\nBy default, feign won't collect any metrics.\n\nBut, it's possible to add metric collection capabilities to any feign client.\n\nMetric Capabilities provide a first-class Metrics API that users can tap into to gain insight into the request/response lifecycle.\n\n\u003e **A Note on Metrics modules**:\n\u003e\n\u003e All the metric-integrations are built in separate modules and not available in the `feign-core` module. You will need to add them to your dependencies.\n\n#### Dropwizard Metrics 4\n\n```java\npublic class MyApp {\n  public static void main(String[] args) {\n    GitHub github = Feign.builder()\n                         .addCapability(new Metrics4Capability())\n                         .target(GitHub.class, \"https://api.github.com\");\n\n    github.contributors(\"OpenFeign\", \"feign\");\n    // metrics will be available from this point onwards\n  }\n}\n```\n\n#### Dropwizard Metrics 5\n\n```java\npublic class MyApp {\n  public static void main(String[] args) {\n    GitHub github = Feign.builder()\n                         .addCapability(new Metrics5Capability())\n                         .target(GitHub.class, \"https://api.github.com\");\n\n    github.contributors(\"OpenFeign\", \"feign\");\n    // metrics will be available from this point onwards\n  }\n}\n```\n\n#### Micrometer\n\n```java\npublic class MyApp {\n  public static void main(String[] args) {\n    GitHub github = Feign.builder()\n                         .addCapability(new MicrometerCapability())\n                         .target(GitHub.class, \"https://api.github.com\");\n\n    github.contributors(\"OpenFeign\", \"feign\");\n    // metrics will be available from this point onwards\n  }\n}\n```\n\n#### Static and Default Methods\nInterfaces targeted by Feign may have static or default methods (if using Java 8+).\nThese allows Feign clients to contain logic that is not expressly defined by the underlying API.\nFor example, static methods make it easy to specify common client build configurations; default methods can be used to compose queries or define default parameters.\n\n```java\ninterface GitHub {\n  @RequestLine(\"GET /repos/{owner}/{repo}/contributors\")\n  List\u003cContributor\u003e contributors(@Param(\"owner\") String owner, @Param(\"repo\") String repo);\n\n  @RequestLine(\"GET /users/{username}/repos?sort={sort}\")\n  List\u003cRepo\u003e repos(@Param(\"username\") String owner, @Param(\"sort\") String sort);\n\n  default List\u003cRepo\u003e repos(String owner) {\n    return repos(owner, \"full_name\");\n  }\n\n  /**\n   * Lists all contributors for all repos owned by a user.\n   */\n  default List\u003cContributor\u003e contributors(String user) {\n    MergingContributorList contributors = new MergingContributorList();\n    for(Repo repo : this.repos(owner)) {\n      contributors.addAll(this.contributors(user, repo.getName()));\n    }\n    return contributors.mergeResult();\n  }\n\n  static GitHub connect() {\n    return Feign.builder()\n                .decoder(new GsonDecoder())\n                .target(GitHub.class, \"https://api.github.com\");\n  }\n}\n```\n\n\n### Async execution via `CompletableFuture`\n\nFeign 10.8 introduces a new builder `AsyncFeign` that allow methods to return `CompletableFuture` instances.\n\n```java\ninterface GitHub {\n  @RequestLine(\"GET /repos/{owner}/{repo}/contributors\")\n  CompletableFuture\u003cList\u003cContributor\u003e\u003e contributors(@Param(\"owner\") String owner, @Param(\"repo\") String repo);\n}\n\npublic class MyApp {\n  public static void main(String... args) {\n    GitHub github = AsyncFeign.builder()\n                         .decoder(new GsonDecoder())\n                         .target(GitHub.class, \"https://api.github.com\");\n\n    // Fetch and print a list of the contributors to this library.\n    CompletableFuture\u003cList\u003cContributor\u003e\u003e contributors = github.contributors(\"OpenFeign\", \"feign\");\n    for (Contributor contributor : contributors.get(1, TimeUnit.SECONDS)) {\n      System.out.println(contributor.login + \" (\" + contributor.contributions + \")\");\n    }\n  }\n}\n```\n\nInitial implementation include 2 async clients:\n- `AsyncClient.Default`\n- `AsyncApacheHttp5Client`\n\n## Maven’s Bill of Material (BOM)\n\nKeeping all feign libraries on the same version is essential to avoid incompatible binaries. When consuming external dependencies, can be tricky to make sure only one version is present.\n\nWith that in mind, feign build generates a module called `feign-bom` that locks the versions for all `feign-*` modules.\n\nThe Bill Of Material is a special POM file that groups dependency versions that are known to be valid and tested to work together. This will reduce the developers’ pain of having to test the compatibility of different versions and reduce the chances to have version mismatches.\n\n\n[Here](https://repo1.maven.org/maven2/io/github/openfeign/feign-bom/11.9/feign-bom-11.9.pom) is one example of what feign BOM file looks like.\n\n#### Usage\n\n```xml\n\u003cproject\u003e\n\n...\n\n  \u003cdependencyManagement\u003e\n    \u003cdependencies\u003e\n      \u003cdependency\u003e\n        \u003cgroupId\u003eio.github.openfeign\u003c/groupId\u003e\n        \u003cartifactId\u003efeign-bom\u003c/artifactId\u003e\n        \u003cversion\u003e??feign.version??\u003c/version\u003e\n        \u003ctype\u003epom\u003c/type\u003e\n        \u003cscope\u003eimport\u003c/scope\u003e\n      \u003c/dependency\u003e\n    \u003c/dependencies\u003e\n  \u003c/dependencyManagement\u003e\n\u003c/project\u003e\n```\n# Form Encoder\n\n[![build_status](https://travis-ci.org/OpenFeign/feign-form.svg?branch=master)](https://travis-ci.org/OpenFeign/feign-form)\n[![maven_central](https://maven-badges.herokuapp.com/maven-central/io.github.openfeign.form/feign-form/badge.svg)](https://maven-badges.herokuapp.com/maven-central/io.github.openfeign.form/feign-form)\n[![License](http://img.shields.io/:license-apache-brightgreen.svg)](http://www.apache.org/licenses/LICENSE-2.0.html)\n\nThis module adds support for encoding **application/x-www-form-urlencoded** and **multipart/form-data** forms.\n\n## Add dependency\n\nInclude the dependency to your app:\n\n**Maven**:\n\n```xml\n\u003cdependencies\u003e\n  ...\n  \u003cdependency\u003e\n    \u003cgroupId\u003eio.github.openfeign.form\u003c/groupId\u003e\n    \u003cartifactId\u003efeign-form\u003c/artifactId\u003e\n    \u003cversion\u003e4.0.0\u003c/version\u003e\n  \u003c/dependency\u003e\n  ...\n\u003c/dependencies\u003e\n```\n\n**Gradle**:\n\n```groovy\ncompile 'io.github.openfeign.form:feign-form:4.0.0'\n```\n\n## Requirements\n\nThe `feign-form` extension depend on `OpenFeign` and its *concrete* versions:\n\n- all `feign-form` releases before **3.5.0** works with `OpenFeign` **9.\\*** versions;\n- starting from `feign-form`'s version **3.5.0**, the module works with `OpenFeign` **10.1.0** versions and greater.\n\n\u003e **IMPORTANT:** there is no backward compatibility and no any gurantee that the `feign-form`'s versions after **3.5.0** work with `OpenFeign` before **10.\\***. `OpenFeign` was refactored in 10th release, so the best approach - use the freshest `OpenFeign` and `feign-form` versions.\n\nNotes:\n\n- [spring-cloud-openfeign](https://github.com/spring-cloud/spring-cloud-openfeign) uses `OpenFeign` **9.\\*** till **v2.0.3.RELEASE** and uses **10.\\*** after. Anyway, the dependency already has suitable `feign-form` version, see [dependency pom](https://github.com/spring-cloud/spring-cloud-openfeign/blob/master/spring-cloud-openfeign-dependencies/pom.xml#L19), so you don't need to specify it separately;\n\n- `spring-cloud-starter-feign` is a **deprecated** dependency and it always uses the `OpenFeign`'s **9.\\*** versions.\n\n## Usage\n\nAdd `FormEncoder` to your `Feign.Builder` like so:\n\n```java\nSomeApi github = Feign.builder()\n                      .encoder(new FormEncoder())\n                      .target(SomeApi.class, \"http://api.some.org\");\n```\n\nMoreover, you can decorate the existing encoder, for example JsonEncoder like this:\n\n```java\nSomeApi github = Feign.builder()\n                      .encoder(new FormEncoder(new JacksonEncoder()))\n                      .target(SomeApi.class, \"http://api.some.org\");\n```\n\nAnd use them together:\n\n```java\ninterface SomeApi {\n\n  @RequestLine(\"POST /json\")\n  @Headers(\"Content-Type: application/json\")\n  void json (Dto dto);\n\n  @RequestLine(\"POST /form\")\n  @Headers(\"Content-Type: application/x-www-form-urlencoded\")\n  void from (@Param(\"field1\") String field1, @Param(\"field2\") String[] values);\n}\n```\n\nYou can specify two types of encoding forms by `Content-Type` header.\n\n### application/x-www-form-urlencoded\n\n```java\ninterface SomeApi {\n\n  @RequestLine(\"POST /authorization\")\n  @Headers(\"Content-Type: application/x-www-form-urlencoded\")\n  void authorization (@Param(\"email\") String email, @Param(\"password\") String password);\n\n  // Group all parameters within a POJO\n  @RequestLine(\"POST /user\")\n  @Headers(\"Content-Type: application/x-www-form-urlencoded\")\n  void addUser (User user);\n\n  class User {\n\n    Integer id;\n\n    String name;\n  }\n}\n```\n\n### multipart/form-data\n\n```java\ninterface SomeApi {\n\n  // File parameter\n  @RequestLine(\"POST /send_photo\")\n  @Headers(\"Content-Type: multipart/form-data\")\n  void sendPhoto (@Param(\"is_public\") Boolean isPublic, @Param(\"photo\") File photo);\n\n  // byte[] parameter\n  @RequestLine(\"POST /send_photo\")\n  @Headers(\"Content-Type: multipart/form-data\")\n  void sendPhoto (@Param(\"is_public\") Boolean isPublic, @Param(\"photo\") byte[] photo);\n\n  // FormData parameter\n  @RequestLine(\"POST /send_photo\")\n  @Headers(\"Content-Type: multipart/form-data\")\n  void sendPhoto (@Param(\"is_public\") Boolean isPublic, @Param(\"photo\") FormData photo);\n\n  // Group all parameters within a POJO\n  @RequestLine(\"POST /send_photo\")\n  @Headers(\"Content-Type: multipart/form-data\")\n  void sendPhoto (MyPojo pojo);\n\n  class MyPojo {\n\n    @FormProperty(\"is_public\")\n    Boolean isPublic;\n\n    File photo;\n  }\n}\n```\n\nIn the example above, the `sendPhoto` method uses the `photo` parameter using three different supported types.\n\n* `File` will use the File's extension to detect the `Content-Type`;\n* `byte[]` will use `application/octet-stream` as `Content-Type`;\n* `FormData` will use the `FormData`'s `Content-Type` and `fileName`;\n* Client's custom POJO for grouping parameters (including types above).\n\n`FormData` is custom object that wraps a `byte[]` and defines a `Content-Type` and `fileName` like this:\n\n```java\n  FormData formData = new FormData(\"image/png\", \"filename.png\", myDataAsByteArray);\n  someApi.sendPhoto(true, formData);\n```\n\n### Spring MultipartFile and Spring Cloud Netflix @FeignClient support\n\nYou can also use Form Encoder with Spring `MultipartFile` and `@FeignClient`.\n\nInclude the dependencies to your project's pom.xml file:\n\n```xml\n\u003cdependencies\u003e\n  \u003cdependency\u003e\n    \u003cgroupId\u003eio.github.openfeign.form\u003c/groupId\u003e\n    \u003cartifactId\u003efeign-form\u003c/artifactId\u003e\n    \u003cversion\u003e4.0.0\u003c/version\u003e\n  \u003c/dependency\u003e\n  \u003cdependency\u003e\n    \u003cgroupId\u003eio.github.openfeign.form\u003c/groupId\u003e\n    \u003cartifactId\u003efeign-form-spring\u003c/artifactId\u003e\n    \u003cversion\u003e4.0.0\u003c/version\u003e\n  \u003c/dependency\u003e\n\u003c/dependencies\u003e\n```\n\n```java\n@FeignClient(\n    name = \"file-upload-service\",\n    configuration = FileUploadServiceClient.MultipartSupportConfig.class\n)\npublic interface FileUploadServiceClient extends IFileUploadServiceClient {\n\n  public class MultipartSupportConfig {\n\n    @Autowired\n    private ObjectFactory\u003cHttpMessageConverters\u003e messageConverters;\n\n    @Bean\n    public Encoder feignFormEncoder () {\n      return new SpringFormEncoder(new SpringEncoder(messageConverters));\n    }\n  }\n}\n```\n\nOr, if you don't need Spring's standard encoder:\n\n```java\n@FeignClient(\n    name = \"file-upload-service\",\n    configuration = FileUploadServiceClient.MultipartSupportConfig.class\n)\npublic interface FileUploadServiceClient extends IFileUploadServiceClient {\n\n  public class MultipartSupportConfig {\n\n    @Bean\n    public Encoder feignFormEncoder () {\n      return new SpringFormEncoder();\n    }\n  }\n}\n```\n\nThanks to [tf-haotri-pham](https://github.com/tf-haotri-pham) for his feature, which makes use of Apache commons-fileupload library, which handles the parsing of the multipart response. The body data parts are held as byte arrays in memory.\n\nTo use this feature, include SpringManyMultipartFilesReader in the list of message converters for the Decoder and have the Feign client return an array of MultipartFile:\n\n```java\n@FeignClient(\n    name = \"${feign.name}\",\n    url = \"${feign.url}\"\n    configuration = DownloadClient.ClientConfiguration.class\n)\npublic interface DownloadClient {\n\n  @RequestMapping(\"/multipart/download/{fileId}\")\n  MultipartFile[] download(@PathVariable(\"fileId\") String fileId);\n\n  class ClientConfiguration {\n\n    @Autowired\n    private ObjectFactory\u003cHttpMessageConverters\u003e messageConverters;\n\n    @Bean\n    public Decoder feignDecoder () {\n      List\u003cHttpMessageConverter\u003c?\u003e\u003e springConverters =\n            messageConverters.getObject().getConverters();\n\n      List\u003cHttpMessageConverter\u003c?\u003e\u003e decoderConverters =\n            new ArrayList\u003cHttpMessageConverter\u003c?\u003e\u003e(springConverters.size() + 1);\n\n      decoderConverters.addAll(springConverters);\n      decoderConverters.add(new SpringManyMultipartFilesReader(4096));\n\n      HttpMessageConverters httpMessageConverters = new HttpMessageConverters(decoderConverters);\n\n      return new SpringDecoder(new ObjectFactory\u003cHttpMessageConverters\u003e() {\n\n        @Override\n        public HttpMessageConverters getObject() {\n          return httpMessageConverters;\n        }\n      });\n    }\n  }\n}\n```\n","funding_links":["https://github.com/sponsors/velo","https://patreon.com/velo132"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopenfeign%2Ffeign","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fopenfeign%2Ffeign","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopenfeign%2Ffeign/lists"}