• Post Reply Bookmark Topic Watch Topic
  • New Topic

"Http 405 Method not allowed" while calling delete rest service method

 
vamshi reddy
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to call DELETE method for my REST web service which I created using enuncaite.

when I try to access get it's working fine .. but unable to access DELETE and POST methods..

please fine my service class below

@Path("add/{id}")
@GET
public Persona readPersona(@PathParam ("id") String personaId);

@Path("store")
@POST
public void storePersona(Persona persona);

@Path("delete/{id}")
@DELETE
public Persona deletePersona(@PathParam("id") String personaId);

on making some research I got a solution to add an handler .. of which code looks like

if(request.getMethod()!=null && request.getMethod().equalsIgnoreCase("GET")
&&request.getPath().contains("/delete"))
{
request.setMethod("DELETE");
}
My website has around 500 url's which I need to delvelop .. and it;s looks really odd for me to do if else condition for each url,

please help me to get better solution than this or please teach me how this is best way for REST web service
 
Ivan Krizsan
Ranch Hand
Posts: 2198
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!
I do not know exactly what causes your problem, but what you have is not a RESTful web service.
You have several paths which contains verbs - this feels more procedurally oriented to me.
Examples of a RESTful approach are:
- A GET to http://www.ivan.com/resources/person/{id} will retrieve the Person resource with the supplied id.
- A GET to http://www.ivan.com/resources/person/ will retrieve a list of all Person resources.
- A POST to http://www.ivan.com/resources/person/ with the representation of a Person will create a new Person resource.
- A DELETE to http://www.ivan.com/resources/person/{id} will remove the Person resource with the supplied id.
- A PUT to http://www.ivan.com/resources/person/{id} with the representation of a Person will update the Person resource with the supplied id.

Yes, the semantics of POST and PUT have been discussed in the past and surely will be again.
Best wishes!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!