0

I am working on a Java Web application Project (Maven Project) using Jersey (JAX-RS).

With postman requests, I am able to process the @DELETE/@PUT requests. but when I am trying to implement those methods in frontend the browser will always show an Error (405 – Method Not Allowed).

I know that HTML doesn't support DELETE/PUT method, but is there a <form method="delete/put">?

or is it even possible to process those requests through the browser?

Thanks

backend Implementation:

@PUT
@Path("/edit/{id}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(APPLICATION_JSON)
public Person editUser(
        @PathParam("id") Long id,
        Student user) {
    return repository.update(user, id); //update User
}

@DELETE
@Path("/delete/{id}")
@Produces(APPLICATION_JSON)
public Person deleteUserById(@PathParam("id") Long id) {
    return repository.delete(id); //delete User
}
Rody
  • 59
  • 7
  • It would be great if you provide your frontend-side code to show us your current attempt. – tschomacker Oct 25 '20 at 14:53
  • No, the only values supported for form method are GET, POST and DIALOG: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/form#attr-method To call a PUT or DELETE endpoint you usually need an AJAX / XMLHTTP request – Roland Kreuzer Oct 25 '20 at 15:06

1 Answers1

0

I'm not sure if it can be done with a form but you can just send XMLHTTP-Requests with JavaScript. A great and simple library for doing so is Axios: https://github.com/axios/axios

Martin Dallinger
  • 369
  • 1
  • 12