Skip to content

Adds base api support via single-inheritance interfaces#246

Merged
codefromthecrypt merged 1 commit into
masterfrom
adrian.base-api
Jul 13, 2015
Merged

Adds base api support via single-inheritance interfaces#246
codefromthecrypt merged 1 commit into
masterfrom
adrian.base-api

Conversation

@codefromthecrypt

Copy link
Copy Markdown

Before this change, apis that follow patterns across a service could
only be modeled by copy/paste/find/replace. Especially with a large
count, this is monotonous and error prone.

This change introduces support for base apis via single-inheritance
interfaces. Users ensure their target interface bind any type variables
and as a result have little effort to create boilerplate apis.

Ex.

@Headers("Accept: application/json")
interface BaseApi<V> {

  @RequestLine("GET /api/{key}")
  V get(@Param("key") String);

  @RequestLine("GET /api")
  List<V> list();

  @Headers("Content-Type: application/json")
  @RequestLine("PUT /api/{key}")
  void put(@Param("key") String, V value);
}

interface FooApi extends BaseApi<Foo> { }

interface BarApi extends BaseApi<Bar> { }

closes #133

@codefromthecrypt

Copy link
Copy Markdown
Author

Before this change, apis that follow patterns across a service could
only be modeled by copy/paste/find/replace. Especially with a large
count, this is monotonous and error prone.

This change introduces support for base apis via single-inheritance
interfaces. Users ensure their target interface bind any type variables
and as a result have little effort to create boilerplate apis.

Ex.

```java
@headers("Accept: application/json")
interface BaseApi<V> {

  @RequestLine("GET /api/{key}")
  V get(@Param("key") String);

  @RequestLine("GET /api")
  List<V> list();

  @headers("Content-Type: application/json")
  @RequestLine("PUT /api/{key}")
  void put(@Param("key") String, V value);
}

interface FooApi extends BaseApi<Foo> { }

interface BarApi extends BaseApi<Bar> { }
```

closes #133
@cloudbees-pull-request-builder

Copy link
Copy Markdown

NetflixOSS » feign » feign-pull-requests #129 SUCCESS
This pull request looks good

@codefromthecrypt

Copy link
Copy Markdown
Author

This PR is sad nobody cares about it..

@spencergibb

spencergibb commented Jul 13, 2015 via email

Copy link
Copy Markdown
Contributor

@zampettim

Copy link
Copy Markdown

I definitely like it, and look forward to testing it out. I'm not that used to using GitHub and their PR system, so it wasn't clear to me that you were done with the work you were doing. I apologize if that caused any confusion.

@spencergibb I'm using Feign via Spring Cloud. Do you have plans to pull this to a branch that I can test with, or should I just pull the feign branch itself?

@spencergibb

Copy link
Copy Markdown
Contributor

@zampettim As soon as a Feign release is done with the PR, we can bring it into then next version of Spring Cloud Netflix.

@spencergibb

Copy link
Copy Markdown
Contributor

@adriancole This would solve this SO

codefromthecrypt pushed a commit that referenced this pull request Jul 13, 2015
Adds base api support via single-inheritance interfaces
@codefromthecrypt
codefromthecrypt merged commit 64bda9d into master Jul 13, 2015
@codefromthecrypt
codefromthecrypt deleted the adrian.base-api branch July 13, 2015 16:44
@codefromthecrypt codefromthecrypt added this to the 8.6.0 milestone Jul 13, 2015
@codefromthecrypt

Copy link
Copy Markdown
Author

8.6.0 on the way!

@bstick12

Copy link
Copy Markdown
Contributor

@adriancole Any chance this could get this merged back to 7.x?

@codefromthecrypt

Copy link
Copy Markdown
Author

@bstick12 I'll try to backport this tomorrow morning. Sorry about the delay!

@codefromthecrypt

Copy link
Copy Markdown
Author

@bstick12 v7.6.0 on the way

@bstick12

bstick12 commented Aug 4, 2015

Copy link
Copy Markdown
Contributor

@adriancole Thanks very much.

@lukosan

lukosan commented Nov 3, 2016

Copy link
Copy Markdown

Can you remember if it was choice to make it only support single-inheritance or is there a fundamental reason why it couldn't or shouldn't support multilevel-inheritance? (or to put it another way: do you think it's worth my looking into making it support multilevel inheritance?)

@codefromthecrypt

codefromthecrypt commented Nov 3, 2016 via email

Copy link
Copy Markdown
Author

@JiabaoZhu

Copy link
Copy Markdown

@adriancole
Sorry, my english is not very good.
I have this problem at the moment, for example:

This code is automatically generated.

public interface TestApiAuto {
    @RequestLine("GET /health")
    String health();

    @RequestLine("GET /all")
    List<Entity> all();
}

This is custom code

public interface TestApi {
    @RequestLine("GET /custom")
    String custom();
}

Now write a client interface

@FeignClient(name = "test")
    public interface TestClient extends TestApi, TestApiAuto  {
}

The result is the wrong: "Only single inheritance supported: TestClient"
Why can't FeignClient support multilevel inheritance?

@JiabaoZhu

Copy link
Copy Markdown

Because TestApiAuto is automatically generated according to the database structure, when the database changes, it will regenerate the code, so some custom methods can not be written in it

velo pushed a commit that referenced this pull request Oct 8, 2024
Adds base api support via single-inheritance interfaces
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support parameterized base apis

7 participants