REST services - testing PUT methods in a browser

I have developed REST services. I can test GET methods with a browser or client application. But those who have PUT methods, I do not know how to use them in a browser ...

For example, I have this method that turns on the lamp after I insert userId:

@PUT
@Path("/lampon")
@Produces({"application/json", "text/plain"})
@Consumes("multipart/form-data")
public boolean turnOnLamp(@FormParam("userId") String userId) throws Exception
{
    boolean response = new LampManager().turnOnLamp(userId);
    return response;
}

In my client application, I do this and it works:

    String webPage = "http://localhost:8080/BliveServices/webresources/services.actuators/lampon";

    URL urlToRequest = new URL(webPage);

    //Authentication

    urlConnection = (HttpURLConnection) urlToRequest.openConnection();
    urlConnection.setReadTimeout(10000);
    urlConnection.setConnectTimeout(15000);
    urlConnection.setRequestMethod("PUT");
    urlConnection.setRequestProperty("Authorization", basicAuth);
    urlConnection.setRequestProperty("Content-type", "multipart/form-data");
    urlConnection.setRequestProperty("Accept", "application/json");
    urlConnection.setDoOutput(true);
    urlConnection.setDoInput(true);

    List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
    nameValuePairs.add(new BasicNameValuePair("userId", "2"));

    (...)

But how can I send userId by browser?

Another thing, I get this message when I create my project:

SEVERE: Resource methods utilizing @FormParam and consuming "multipart/form-data" are no longer supported. See @FormDataParam.

thank

+5
source share
2 answers

If you want to test REST-Webservice with your browser, you must install the plugin.

If you use Google Chrome, you can install the REST Console. I also use this plugin to test my web service.

https://chrome.google.com/webstore/detail/rest-console/cokgbflfommojglbmbpenpphppikmonn

Firefox REST-Client

https://addons.mozilla.org/en-us/firefox/addon/restclient/

REST CLient Safari http://restclient.net/

Opera Simple REST-Client

https://addons.opera.com/en/extensions/details/simple-rest-client/

" " application/x-www-form-urlencoded '

+9

- , jQuery jQuery.ajax(). (http://api.jquery.com/jQuery.ajax/)

:

$.ajax({
  url: "test-url",
  type: "PUT",
  data: {userid: 1}
})

put-request url .

+3

All Articles