0

i've got a rest server that listens to PUT's with a pair of query params. The test cases of it's api uses a Jersey client and look like this :

 public void putV1ItemsIdShouldSaveNewObj() throws Exception {
        String json = new ObjectMapper().writeValueAsString(obj);
        itemsTarget = itemsTarget.queryParam("x",2);
        itemsTarget = itemsTarget.queryParam("y",2);
        Response r = itemsTarget.request().put(Entity.text(json));
        String jsonans = r.readEntity(String.class);
        assertThat(jsonans, is(not(nullValue())));
    }

How can I make this kind of puts with arguments in XMLHttpRequest ?

        req.open("PUT", "http://00.00.00.00:8080/PATH/obj?x=40&Y=50", true);
        req.send("{\"atr1\":\"aaaa\",\"atr2\":3}");

Appending to the target url is not working

Lau Llobet
  • 577
  • 7
  • 21
  • You mean to use a library ? I'm planning to do it without library (only JS) since the app should not be very heavy – Lau Llobet Jun 23 '15 at 15:04
  • 1
    You are sending request is Node or javascript? – Manwal Jun 23 '15 at 15:04
  • Have a look at this post. http://stackoverflow.com/questions/4477454/how-is-a-http-put-request-typically-issued - It seems that you misunderstand the way a url is constructed for a PUT request. – enhzflep Jun 23 '15 at 15:09
  • 1
    @Manwal — "Node or javascript" is like asking "Ford or road vehicle?". If you mean "Browser or Node?" then the question says it uses XMLHttpRequest, which strongly implies a browser (since, while there are XMLHttpRequest implementations for Node (and I've used one in the past) it is more usual to use one of the other HTTP libraries). – Quentin Jun 23 '15 at 15:18
  • @Quentin my sincere apologies for this but i thought `req.send(` code of node. – Manwal Jun 23 '15 at 15:21
  • @enhzflep I understand what you mean, in fact my PUT is actually idempotent ant the two parameters are in fact repeaded in the attributes of the object inside the put, the thing is that I didin't want to parse the JSON if thoose parameters had certain properties in order to save computational time. – Lau Llobet Jun 23 '15 at 15:33

0 Answers0