GithubHelp home page GithubHelp logo

openfeign / feign-cdi Goto Github PK

View Code? Open in Web Editor NEW
7.0 2.0 2.0 95 KB

CDI provider for injecting Feign types

License: Apache License 2.0

Java 51.66% Shell 33.41% Batchfile 14.93%
feign-interfaces cdi http-client

feign-cdi's Introduction

Feign CDI

Integration for OpenFeign with Java Contexts & Dependency Injection, allowing you to inject your type safe restful interfaces

Adding to your project

Feign CDI is built using Apache Maven. Artifacts are published, though there's only a single artifact at this time.

<dependency>
    <groupId>io.github.openfeign.cdi</groupId>
    <artifactId>feign-cdi</artifactId>
    <version>0.1.6</version>
</dependency>

Creating clients

Feign CDI uses the normal Feign interfaces for declaring your rest client. You can add additional annotations to your interface to support CDI integration

@FeignClient

public @interface FeignClient {
    Logger.Level logLevel() default Logger.Level.NONE;

    Class<? extends Contract> contract() default Contract.Default.class;

    Class<? extends Client> client() default CDIClient.class;

    Class<? extends Decoder> decoder() default Decoder.Default.class;

    Class<? extends Encoder> encoder() default Encoder.Default.class;

    Class<? extends ErrorDecoder> errorDecoder() default ErrorDecoder.Default.class;

    Class<? extends InvocationHandlerFactory> invocationHandlerFactory() default InvocationHandlerFactory.Default.class;

    Class<? extends Logger> logger() default Logger.NoOpLogger.class;

    Class<? extends Retryer> retryer() default Retryer.Default.class;

    Class<? extends RequestInterceptor>[] requestInterceptors() default {};

    String url();

    int connectTimeoutMillis() default 10 * 1000;

    int readTimeoutMillis() default 60 * 1000;

    boolean decode404() default false;
}

@FeignClient is an annotation to place on your interfaces where you can define the normal configuration options for Feign interfaces. The defaults here match the defaults in Feign.Builder, except for the client implementation to support no-arg constructors.

Any class configured here will follow one of two options:

  • Managed CDI Beans
  • No-args constructor

Any classes you use here should be normal scoped beans - don't use @Dependent as there is no creational context. If no bean is found, then this extension will instantiate the class using its default constructor.

Managing Scopes

Any @Scope declared on the interface will be used by the bean.

Registering the extension

The CDI extension class to register is feign.cdi.impl.FeignExtension, which will add annotated client beans for each interface discovered.

feign-cdi's People

Contributors

adriancole avatar johnament avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

feign-cdi's Issues

Feign CDI - Optional Hystrix Integration

Add support for the optional capabilities provided in Hystrix module. Since the module provides its own builder, need to leverage that builder instead of the native builder.

Implement a Feign CDI Module

From @johnament on December 4, 2016 13:30

Feign is an amazing library for working with type safe REST clients. It simplifies a lot of day to day development work being able to leverage the client.

CDI is a dependency injection tool. While a user can define producer methods there is still the boilerplate overhead that they may have to deal with.

I'd like to propose adding a CDI module, which will look for interfaces supporting Feign and provide injection points to CDI users to simply inject their clients. No additional development, all annotation based and configured as needed.

It should provide some kind of fallback to look for common builders for interfaces and leverage those whenever possible.

Copied from original issue: OpenFeign/feign#500

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.