Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Extension Proposal] easy-retrofit for Quarkus Extension #40585

Closed
liuziyuan opened this issue May 13, 2024 · 9 comments · Fixed by quarkiverse/quarkiverse-devops#234
Closed
Labels
area/quarkiverse This issue/PR is part of the Quarkiverse organization kind/extension-proposal Discuss and Propose new extensions

Comments

@liuziyuan
Copy link

liuziyuan commented May 13, 2024

Description

Quickly using Retrofit 2 in the Quarkus project, the easy-retrofit provides an annotation based configuration to create Retrofit instances, and enhances general functionality through more annotations.
Currently, this project has completed its core functions within the Spring boot framework。
Retrofit is A type-safe HTTP client for Android and Java,Retrofit provides both synchronous and asynchronous HTTP requests。

easy retrofit website on github easy-retrofit-spring-boot-stater

Repository name

quarkus-easy-retrofit

Short description

easy-retrofit-client provides an annotation based configuration to create Retrofit instances, and enhances general functionality through more annotations.

Repository Homepage URL

https://quarkiverse.github.io/quarkiverse-docs/quarkus-easy-retrofit/dev/

Repository Topics

  • quarkus-extension
  • http-client
  • retrofit

Team Members

  • liuziyuan

Additional context

No response

@liuziyuan liuziyuan added area/quarkiverse This issue/PR is part of the Quarkiverse organization kind/extension-proposal Discuss and Propose new extensions labels May 13, 2024
@quarkus-bot
Copy link

quarkus-bot bot commented May 13, 2024

/cc @aloubyansky (extension-proposal), @gastaldi (extension-proposal), @gsmet (extension-proposal), @maxandersen (extension-proposal)

@maxandersen
Copy link
Contributor

I know about https://square.github.io/retrofit/, but what is easy retrofit? is that some other thing?

biggest issue I have with retrofit is that it seem to depend on okhttp which then drags in a lot of kotlin stdlib dependencies. that's unfortunate.

but +1 for enabling use of retrofit from Quarkus - just be cautious about dependency chain issues this can trigger.

@liuziyuan
Copy link
Author

liuziyuan commented May 14, 2024

what is easy retrofit? is that some other thing?

The core of easy-retrofit is to implicitly provide retrofit instance injection to the DI framework and enhance the function with more annotations.
other thing is, Provides a extension function that can extend the underlying OKHttp Interceptor of Retrofit. The current extension can be seen in the project extension folder.

for example , on official retrofit ,
first, you need to define an interface .second ,you need create a instance of interface, last, you could access http request.

public interface GitHubService {
  @GET("users/{user}/repos")
  Call<List<Repo>> listRepos(@Path("user") String user);
}

Retrofit retrofit = new Retrofit.Builder()
    .baseUrl("https://api.github.com/")
    .build();
GitHubService service = retrofit.create(GitHubService.class);

Call<List<Repo>> repos = service.listRepos("octocat");

on easy retrofit,
You just need to declare @EnablingRetrofit Annotation ,second, define an interface. last, inject interface by DI framework,
Then you could access http request

@RetrofitBuilder(baseUrl = "${app.hello.url}")
public interface HelloApi {
    @GET("v1/hello/{message}")
    Call<ResponseBody> hello(@Path("message") String message);
}

@Autowired
private HelloApi helloApi;

@GetMapping("/{message}")
public ResponseEntity<String> hello(@PathVariable String message) throws IOException {
    final ResponseBody body = helloApi.hello(message).execute().body();
    return ResponseEntity.ok(body.string());
}

Actually, I have already completed the integration of the easy retrofit on quarks extension at my local. Do you need me to push the local git project to GitHub and review it?

and last, @maxandersen thank you +1 for my project extension proposal , I want to know under what circumstances would a project be created for easy retrofit

For more examples, you can take a look at easy-retrofit-readme, but the English readme is not a latest, and for Spring Framework demo at here.

@liuziyuan
Copy link
Author

@maxandersen @gastaldi @aloubyansky @gsmet I would like to know when I can create a project for the easy retrofit extension in the Quarkiverse Hub

@gastaldi
Copy link
Contributor

@liuziyuan I can create a repository for you. Have you already created a protoype as a Quarkus extension (maybe in your personal org) so we can take a look or the plan is to start from zero?

@liuziyuan
Copy link
Author

liuziyuan commented May 16, 2024

@liuziyuan I can create a repository for you. Have you already created a protoype as a Quarkus extension (maybe in your personal org) so we can take a look or the plan is to start from zero?

@gastaldi In my local , the core functions of the Quarkus easy retrofit project have been completed and I have pushed quarkus-easy-retrofit to my GitHub. This project is just a demo for you to see

you can run integration-tests sub-module, http://localhost:8080/retrofit-client ,and observe the value returned by the retrofit interface

@gastaldi
Copy link
Contributor

@liuziyuan quarkiverse/quarkus-easy-retrofit is now provisioned. Welcome to Quarkiverse! See hub.quarkiverse.io/checklist/#after-the-repository-is-created for the next steps

@maxandersen
Copy link
Contributor

thanks for the info @liuziyuan - i took a look at the integration test sub module and wondered what these adapters are for: https://github.com/liuziyuan/quarkus-easy-retrofit/tree/main/integration-tests/src/main/java/io/quarkiverse/easy/retrofit/client/it/retrofit ?

are those something users need to add?

@liuziyuan
Copy link
Author

liuziyuan commented May 17, 2024

thanks for the info @liuziyuan - i took a look at the integration test sub module and wondered what these adapters are for: https://github.com/liuziyuan/quarkus-easy-retrofit/tree/main/integration-tests/src/main/java/io/quarkiverse/easy/retrofit/client/it/retrofit ?

are those something users need to add?

Essentially, The @RetrofitBuilder is a substitute for Retrofit Retrofit.Builder(), Retrofit.Builder() provides some methods to assemble the final Retrofit object, and in Easy Retrofit, the same applies.
As for the other files, they are used by me to test the Easy Retrofit Extension function and can be ignored in the demo
For more usage, you can see readme。easy Retrofit readme advanced configuration

@RetrofitBuilder(baseUrl = "${app.url}" ,
        addConverterFactory = {JacksonConvertFactoryBuilder.class},
        addCallAdapterFactory = {BodyCallAdapterFactoryBuilder.class, GuavaCallAdapterFactoryBuilder.class},
        validateEagerly = false,
        globalOverwriteRule = OverrideRule.LOCAL_FIRST)
//@RetrofitInterceptor(handler = TestInterceptor.class)
public interface BaseApi {

    @GET("api/hello")
    Call<ResponseBody> hello();

    @GET("backend/v1/hello/abc")
    HelloBean helloBean2();
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/quarkiverse This issue/PR is part of the Quarkiverse organization kind/extension-proposal Discuss and Propose new extensions
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants