Ok so this is the code on the server side i just have question on how is the path gonna be defined on the client’s side.
This is the method on the server
@Path("{index}/{product}/{amount}")
@PUT
@Produces("text/plain")
public String editTable (@PathParam("index") Integer index, @PathParam("product") String product, @PathParam("amount") Integer amount)
{...}
Now on the client side
{url = new URL( "http://localhost:8080/OrderService/service/tableservice/"+num+"/"+product+"/"+amount);
.....}
/”+num+”/”+product+”/”+amount);
Is this the correct syntax??
Also can the num and amount be integers while the product a string or am i gonna have a problem with it?
You will have problems if the product name has ‘unsafe’ URL characters in it. Which will probably be the case. To get around that you could URL encode the name before appending it to the URL.
But I think you should rethink your PATH definition in the first place. A good resource endpoint should uniquely identify it. But in your case you are including an
amountfield in the URL! Which means depending on who is ordering the product the resource URL is changing:Customer A orders 2 Furbies:
Customer B orders 1 Furbie
But in both cases the customers are trying to order the same thing – a Furbie! This is not RESTful. Instead you should define a unique resource endpoint, then send the additional order information as appended data. So for example:
You will notice I removed the index field as well, you can add that back in if absolutely required. You will notice I also added tacked an
orderssuffix to the end of the URL. To indicate that you are PUT’ing an updated representation for an order made for a product.