eclipse / microprofile-rest-client

MicroProfile Rest Client
Apache License 2.0
143 stars 72 forks source link

Allow default data on request (query params, headers, payload) #315

Open FreifeldRoyi opened 3 years ago

FreifeldRoyi commented 3 years ago

(Continuing a conversation with @andymc12 from Gitter channel) I would like to create requests with default data with no extra parameters. Headers are already provided with RegisterClientHeaders but QueryParam and actual JSON payloads are not implemented:

e.g

// instead of 
@Get("/")
SomeObject fetchItems(@QueryParam("asd") String myParam);

// use something like:
@Get("/")
@DefaultQueryParam(name="asd", value="my-val")
SomeObject fetchItems();

// or:
@Get("/")
@RegisterClientParams(QueryParamsProvider.class)
SomeObject fetchItems();

// or some other idea =)

Same thing goes for actual json payload

jamezp commented 9 months ago

Given we cannot find the Gitter history, could you explain more some more details of the issue? Would using something like @QueryParam("asd") @DefaultValue("my-val") not work here?

FreifeldRoyi commented 4 months ago

Hi @jamezp. I think that @DefauleValue("my-val") would partially help. When I originally posted on Gitter, @andymc12 said that it is not portable and not part of the standard. I'm not sure if it is now. Here's a link to the Gitter history

If I understand what I meant, since it was a long time ago - I suggested 2 options:

  1. Simple way with @DefaultValue or @DefaultQueryParam
  2. I think it's like RegisterHeaderParams where there's a class that can somehow calculate the required data and return it to the function. Not sure when I would use it though 🤷🏼‍♂️

Would be awesome to do the same thing for payload as well

At that time, as far as I remember, I needed to set the headers, query params, payload, path params in one single function call. It created a telescopic function. Also, most of the time, I needed the same things over and over again, so writing them down in several places in my code just didn't look good. So I had to wrap it with another client, and I think it just beats the purpose of creating a standard way of handling REST clients