Page 1 of 1

QUERIES for MAking DELETE < PUT AND POST rest services

Posted: Wed May 08, 2013 5:27 am
by ANITHA
Hi . i am unable to make DELETE , PUT AND POST REQUESTS VIA REST SERVICES.


Uri{items/itemid) how to invoke this? please give some instance, i mean example.

Pls give one example for each of delete post and put request. I'm getting method not allowed when i invoke

localhost:8080/api/cart/items/1001

Re: QUERIES for MAking DELETE < PUT AND POST rest services

Posted: Wed May 08, 2013 8:48 am
by phillipuniverse
You are probably 'invoking' them with HTTP GET requests. DELETE, PUT and POST are all 3 different HTTP methods: http://www.w3schools.com/tags/ref_httpmethods.asp

You cannot just simply type in 'localhost:8080/api/cart/items/1001' into a browser and expect it to remove it. When you put anything into a browser window and hit 'enter' it executes an http GET method. You will have to use some other API or tool or whatever in order to execute additional HTTP methods. Personally, I like to use the Rest Console chrome plugin: https://chrome.google.com/webstore/deta ... monn?hl=en.

Here's a screenshot of me about to send a DELETE request to /api/cart/items/1001 and requesting the response to be returned back in JSON: http://cl.ly/image/2s0O0n0P3Z0w

Re: QUERIES for MAking DELETE < PUT AND POST rest services

Posted: Fri May 10, 2013 1:51 am
by ANITHA
Hi

I did not understand your reply. Do i need to add some other plugin or anything else?
Tell me wat to do in detail

Re: QUERIES for MAking DELETE < PUT AND POST rest services

Posted: Fri May 10, 2013 2:05 am
by phillipuniverse
I'm not really sure how else to explain it. Whatever client that you are using to send the HTTP requests to the Broadleaf needs to use the correct HTTP method (PUT, DELETE, POST or GET) when it sends the request. The default method is usually GET so you will have to change the HTTP method being used in your client-side code.

What exactly have you tried and what is unclear? Maybe if you give a little more detail with the exact steps you are following (like the client-side library you are using, if you're just going to those URLs in the browser, etc) then we'll be able to help more.

Re: QUERIES for MAking DELETE < PUT AND POST rest services

Posted: Fri May 10, 2013 2:07 am
by phillipuniverse
Also, the plugin I was referring to is a chrome plugin that can be used to test REST APIs in order to give you a human-readable output and ensure that the APIs are working. That is its only purpose. You will probably use some other client-side API (like Apache's HttpClient or Spring's RestTemplate) to actually make the requests in your client-side application.

Re: QUERIES for MAking DELETE < PUT AND POST rest services

Posted: Mon May 13, 2013 12:38 am
by ANITHA
hi I was using only those url in web browser. i'm using http client jar. Even though i specify correct item id i get method not allowed error message.

Re: QUERIES for MAking DELETE < PUT AND POST rest services

Posted: Mon May 13, 2013 4:29 am
by ANITHA
Hi..

I have called delete request by invoking

localhost:8080/restapi/cart/items/954.

Actually there is an item with product id=950 and its in cart. I'm trying to remove that from cart by invoking the above uri. But i get a method not allowed message. Am i using a proper uri to remove that item with product id=950 or if not wat is the proper way of me doing it. i've attached the snap of it you can view it as well

Thanks ,
Anita

Re: QUERIES for MAking DELETE < PUT AND POST rest services

Posted: Mon May 13, 2013 9:44 am
by phillipuniverse
As I said, you cannot just simply type that URL in a browser and hit enter for POST, PUT and DELETE method requests. When you type a URL into a browser, it executes an HTTP GET request. You need to execute an HTTP DELETE request. This is why I recommended downloading the Rest Console plugin so that you can test the APIs that you cannot exercise with normal GET requests (meaning, typing them into a browser). The other HTTP methods will never ever work if you just type the URL into the browser and hit enter.

If you are using Apache's HttpClient, you have to do something like:

Code: Select all


HttpClient client 
= new HttpClient();
//ensure that you are executing an HTTP DELETE request
HttpMethod method = new DeleteMethod("localhost:8080/restapi/cart/items/954");
client.execute(method);
 

Re: QUERIES for MAking DELETE < PUT AND POST rest services

Posted: Wed May 15, 2013 1:22 am
by ANITHA
ya i tried using rest console and tested it works fine. thank you