Skip to content

Commit

Permalink
Add a quickstart for the default REST Client
Browse files Browse the repository at this point in the history
Let's make it consistent with the RESTEasy Client
  • Loading branch information
gsmet committed Mar 11, 2024
1 parent 73252ed commit 43ee48b
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{#include readme-header /}
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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<MyRemoteService.Extension> restClientExtensions = myRemoteService.getExtensionsById("io.quarkus:quarkus-hibernate-validator");
* }
* }
*/
@RegisterRestClient(baseUri = "https://stage.code.quarkus.io/api")
public interface MyRemoteService {

@GET
@Path("/extensions")
Set<Extension> getExtensionsById(@QueryParam("id") String id);

class Extension {
public String id;
public String name;
public String shortName;
public List<String> keywords;
}
}
Original file line number Diff line number Diff line change
@@ -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<Extension>

data class Extension(val id: String, val name: String, val shortName: String, val keywords: List<String>)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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."

0 comments on commit 43ee48b

Please sign in to comment.