Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #35755

Re: Rest parameter without value

Path csiph.com!aioe.org!.POSTED!not-for-mail
From Arne Vajhøj <arne@vajhoej.dk>
Newsgroups comp.lang.java.programmer
Subject Re: Rest parameter without value
Date Fri, 14 Oct 2016 14:49:09 -0400
Organization Aioe.org NNTP Server
Lines 64
Message-ID <ntr9b4$1v2r$1@gioia.aioe.org> (permalink)
References <m3lgxr8681.fsf@saunalahti.fi>
NNTP-Posting-Host 68.229.81.69
Mime-Version 1.0
Content-Type text/plain; charset=windows-1252; format=flowed
Content-Transfer-Encoding 7bit
X-Trace gioia.aioe.org 1476470948 64603 68.229.81.69 (14 Oct 2016 18:49:08 GMT)
X-Complaints-To abuse@aioe.org
NNTP-Posting-Date Fri, 14 Oct 2016 18:49:08 +0000 (UTC)
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0
Cache gioia.aioe.org 1476470948 64603 68.229.81.69 1476470948 68.229.81.69 2097 779 G6elUPukRmq7RKXfYXJcnw 68.229.81 1 0
In-Reply-To <m3lgxr8681.fsf@saunalahti.fi>
Xref csiph.com comp.lang.java.programmer:35755

Show key headers only | View raw


On 10/14/2016 8:28 AM, Jukka Lahtinen wrote:
> I have been working with java, but REST is new to me.
> Now I am working on a REST client for the first time.
> I have already managed to use a rest request with a path parameter and
> another one with query parameters.
>
> Now the request with a path parameter should in some occasions contain a
> parameter without a value.

> What I have tried looks essentially like this:
>
> String url = "http://machine/path/v3.0/{keyvalue}";
> Private javax.ws.rs.Client client; // initialized in the constructor
> ..
>
> private Object makeCall(String keyvalue, boolean b) {
>   UriBuilder builder = UriBuilder.fromUri( url ).path( path ).
>                         resolveTemplate( "keyvalue", keyvalue );
>   WebTarget target = client.target( builder );
>   if (b) {
>     target = target.queryParam("foo", "");
>   }
>   Response resp = target.request().headers(makeHeaders()).get();
>   Object ret = null;
>   ..
>   // resp handling not shown here
>   ..
>   return ret;
> }
>
> Debugging this, I lookd at target after the target.queryParam call and
> noticed that target contains a ResteasyUriBuilder object uriBuilder,
> where the attribute "query" now contains "foo=".
> So this apparently will make the actual url look like this:
>
> http://machine/path/v3.0/keyvalue?foo=
>
> But I need it without the equals at the end. How do I do that?
>
> I also tried passing null to the target.queryParam call instead of the
> empty String,
>   target = target.queryParam("foo", null);
> but that way target.uriBuildeer.query remains null.

The API may not support it, because it does not make much sense
in REST.

http://host/resource  ~=  SELECT * FROM resource

http://host/resource/value  ~=  SELECT * FROM resource WHERE id = value

http://host/resource?nam=val  ~=  SELECT * FROM resource WHERE nam=val

http://host/resource?nam  ~=  ????

But as fallback mechanism you can always drop the JAX-RS client classes
and revert to Java HttpURLCOnnection or Apache HttpClient with a JSON
library. That gives you full freedom to do whatever you want.

Arne



Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Rest parameter without value Jukka Lahtinen <jtfjdehf@hotmail.com.invalid> - 2016-10-14 15:28 +0300
  Re: Rest parameter without value Arne Vajhøj <arne@vajhoej.dk> - 2016-10-14 14:49 -0400
    Re: Rest parameter without value Jukka Lahtinen <jtfjdehf@hotmail.com.invalid> - 2016-10-17 08:48 +0300
      Re: Rest parameter without value Jukka Lahtinen <jtfjdehf@hotmail.com.invalid> - 2016-10-17 09:50 +0300
  Re: Rest parameter without value 4ndre4 <626401fd-4bc7-4f8f-b641-563ae0f72920@626401fd-4bc7-4f8f-b641-563ae0f72920.invalid> - 2016-10-14 21:16 +0100
  Re: Rest parameter without value Jukka Lahtinen <jtfjdehf@hotmail.com.invalid> - 2016-10-17 08:30 +0300

csiph-web