From 43ee48b4d303e24e9a57d6db26f221c2f2f571d8 Mon Sep 17 00:00:00 2001 From: Guillaume Smet Date: Mon, 11 Mar 2024 18:59:52 +0100 Subject: [PATCH] Add a quickstart for the default REST Client Let's make it consistent with the RESTEasy Client --- .../base/README.tpl.qute.md | 1 + .../rest-client-codestart/codestart.yml | 13 +++++++ .../main/java/org/acme/MyRemoteService.java | 37 +++++++++++++++++++ .../main/kotlin/org/acme/MyRemoteService.kt | 29 +++++++++++++++ .../resources/META-INF/quarkus-extension.yaml | 4 +- 5 files changed, 81 insertions(+), 3 deletions(-) create mode 100644 devtools/project-core-extension-codestarts/src/main/resources/codestarts/quarkus/extension-codestarts/rest-client-codestart/base/README.tpl.qute.md create mode 100644 devtools/project-core-extension-codestarts/src/main/resources/codestarts/quarkus/extension-codestarts/rest-client-codestart/codestart.yml create mode 100644 devtools/project-core-extension-codestarts/src/main/resources/codestarts/quarkus/extension-codestarts/rest-client-codestart/java/src/main/java/org/acme/MyRemoteService.java create mode 100644 devtools/project-core-extension-codestarts/src/main/resources/codestarts/quarkus/extension-codestarts/rest-client-codestart/kotlin/src/main/kotlin/org/acme/MyRemoteService.kt diff --git a/devtools/project-core-extension-codestarts/src/main/resources/codestarts/quarkus/extension-codestarts/rest-client-codestart/base/README.tpl.qute.md b/devtools/project-core-extension-codestarts/src/main/resources/codestarts/quarkus/extension-codestarts/rest-client-codestart/base/README.tpl.qute.md new file mode 100644 index 0000000000000..405280158877d --- /dev/null +++ b/devtools/project-core-extension-codestarts/src/main/resources/codestarts/quarkus/extension-codestarts/rest-client-codestart/base/README.tpl.qute.md @@ -0,0 +1 @@ +{#include readme-header /} \ No newline at end of file diff --git a/devtools/project-core-extension-codestarts/src/main/resources/codestarts/quarkus/extension-codestarts/rest-client-codestart/codestart.yml b/devtools/project-core-extension-codestarts/src/main/resources/codestarts/quarkus/extension-codestarts/rest-client-codestart/codestart.yml new file mode 100644 index 0000000000000..067c3561eecbf --- /dev/null +++ b/devtools/project-core-extension-codestarts/src/main/resources/codestarts/quarkus/extension-codestarts/rest-client-codestart/codestart.yml @@ -0,0 +1,13 @@ +name: rest-client-codestart +ref: rest-client +type: code +tags: extension-codestart +metadata: + title: REST Client + description: Invoke different services through REST with JSON + related-guide-section: https://quarkus.io/guides/rest-client +language: + base: + dependencies: + - io.quarkus:quarkus-rest-client + - io.quarkus:quarkus-rest-client-jackson diff --git a/devtools/project-core-extension-codestarts/src/main/resources/codestarts/quarkus/extension-codestarts/rest-client-codestart/java/src/main/java/org/acme/MyRemoteService.java b/devtools/project-core-extension-codestarts/src/main/resources/codestarts/quarkus/extension-codestarts/rest-client-codestart/java/src/main/java/org/acme/MyRemoteService.java new file mode 100644 index 0000000000000..9cc8e8ba1e27c --- /dev/null +++ b/devtools/project-core-extension-codestarts/src/main/resources/codestarts/quarkus/extension-codestarts/rest-client-codestart/java/src/main/java/org/acme/MyRemoteService.java @@ -0,0 +1,37 @@ +package org.acme; + +import org.eclipse.microprofile.rest.client.inject.RegisterRestClient; + +import jakarta.ws.rs.GET; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.QueryParam; +import java.util.List; +import java.util.Set; + +/** + * To use it via injection. + * + * {@code + * @Inject + * @RestClient + * MyRemoteService myRemoteService; + * + * public void doSomething() { + * Set restClientExtensions = myRemoteService.getExtensionsById("io.quarkus:quarkus-hibernate-validator"); + * } + * } + */ +@RegisterRestClient(baseUri = "https://stage.code.quarkus.io/api") +public interface MyRemoteService { + + @GET + @Path("/extensions") + Set getExtensionsById(@QueryParam("id") String id); + + class Extension { + public String id; + public String name; + public String shortName; + public List keywords; + } +} diff --git a/devtools/project-core-extension-codestarts/src/main/resources/codestarts/quarkus/extension-codestarts/rest-client-codestart/kotlin/src/main/kotlin/org/acme/MyRemoteService.kt b/devtools/project-core-extension-codestarts/src/main/resources/codestarts/quarkus/extension-codestarts/rest-client-codestart/kotlin/src/main/kotlin/org/acme/MyRemoteService.kt new file mode 100644 index 0000000000000..e28a0ae228c7d --- /dev/null +++ b/devtools/project-core-extension-codestarts/src/main/resources/codestarts/quarkus/extension-codestarts/rest-client-codestart/kotlin/src/main/kotlin/org/acme/MyRemoteService.kt @@ -0,0 +1,29 @@ +package org.acme + +import org.eclipse.microprofile.rest.client.inject.RegisterRestClient +import jakarta.ws.rs.GET +import jakarta.ws.rs.Path +import jakarta.ws.rs.QueryParam + +/** + * To use it via injection. + * + * ```kotlin + * @Inject + * @RestClient + * lateinit var myRemoteService: MyRemoteService + * + * fun doSomething() { + * val restClientExtensions = myRemoteService.getExtensionsById("io.quarkus:quarkus-rest-client") + * } + * ``` + */ +@RegisterRestClient(baseUri = "https://stage.code.quarkus.io/api") +interface MyRemoteService { + + @GET + @Path("/extensions") + fun getExtensionsById(@QueryParam("id") id: String): Set + + data class Extension(val id: String, val name: String, val shortName: String, val keywords: List) +} diff --git a/extensions/resteasy-reactive/rest-client/runtime/src/main/resources/META-INF/quarkus-extension.yaml b/extensions/resteasy-reactive/rest-client/runtime/src/main/resources/META-INF/quarkus-extension.yaml index de79bd08bce04..89f5ea5e860c9 100644 --- a/extensions/resteasy-reactive/rest-client/runtime/src/main/resources/META-INF/quarkus-extension.yaml +++ b/extensions/resteasy-reactive/rest-client/runtime/src/main/resources/META-INF/quarkus-extension.yaml @@ -12,12 +12,10 @@ metadata: status: "stable" guide: "https://quarkus.io/guides/rest-client" codestart: - name: "rest" - kind: "core" + name: "rest-client" languages: - "java" - "kotlin" - - "scala" artifact: "io.quarkus:quarkus-project-core-extension-codestarts" config: - "quarkus.rest-client-reactive."