Skip to content

Feign generic clients #457

@jmnarloch

Description

@jmnarloch

Since the update of Feign to version 8.6.0 now it's possible to have whole interface hierarchies used as a clients.

I was trying to facilitate this idea in a form:

public interface CrudClient<T> {

    

    @RequestMapping(method = RequestMethod.POST, value = "/")

    long save(T entity);

    

    @RequestMapping(method = RequestMethod.PUT, value = "/{id}")
    
    void update(@PathVariable("id") long id, T entity);

    

    @RequestMapping(method = RequestMethod.GET, value = "/{id}")
    
    T get(@PathVariable("id") long id);

   

    @RequestMapping(method = RequestMethod.DELETE, value = "/{id}")
    
    void delete(@PathVariable("id") long id);

}

The only problem with this approach is that you will have to alter the specific paths for the concreate clients. The only supported way at the moment is to specify the explicit url like. 'http://localhost/users'

But it would be awaseome if it would be possible to do that with enabled Eureka discovery and Ribbon load balancing. Through one of the possible syntaxes:

@FeignClient("localapp/users")
public interface UsersClient extends CrudClient<User> {


}

or

@FeignClient("localapp")

@RequestMapping(value = "/users")

public interface UsersClient extends CrudClient<User> {


}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions