簡體   English   中英

帶有 Quarkus 的 jax-rs/microprofile 客戶端中的可變長度端點

[英]Variable length endpoints in jax-rs/microprofile client with Quarkus

我面臨以下問題,並且能夠找到適當的解決方法。

作為一個用例示例,讓我們想象一個 Rest 客戶端從服務器獲取一個 json object,其中請求是到 object 的路徑。這個 api 不接受查詢參數和正文,並且沒有可用的目錄。

說我有以下 RestClient:

@Path("/json")
@RegisterRestClient(configKey="json-api")
public interface JsonService {

    @GET
    @Path("/{MyVariableLengthEndpoint}")
    Response getJson(@PathParam("MyVariableLengthEndpoint") ????? endpoint);
}

請求示例可以是:

  • /json/employees/Dwight/jobs/assistantRegionalManager/salary
  • /json/games/theLastOfUs/rating

傳遞帶有 / 字符的字符串會使用 % 進行編碼。 為了繞過這個,我試過:

  • 使用@Encoded 注解
  • 在路徑參數{MyVariableLengthEndpoint: .*}中添加正則表達式
  • 傳遞List<PathSegment>

這些都沒有用。

有沒有正確的方法來做到這一點?

您應該在 @Path 定義中使用 Regex,如下所示:

@GET
@Path(“/{varPath : .+}”)
Response getJson(@PathParam(“varPath”) String endpoint);

這將匹配 /json 之后的任何內容。

有關更多信息,請在 Google 上搜索:“JAXRS path Regex”。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM