title: DELETE giving 405 in postman
body: <p>I am new to restful webservices and following java restful api tutorials.
  all the HTTP requests are working fine except the DELETE request.
  i am facing the same issue as described in this link.
  <a href="https://stackoverflow.com/questions/41931864/rest-http-status-405-method-not-allowed">REST - HTTP Status 405 - Method Not Allowed</a></p>
  
  <p>also , in the predefined header values postman is showing
  allow →GET,OPTIONS,PUT(image link is below)</p>
  
  <p>i am following the correct syntax and url format as per the specification(pasted in image) but delete is not working.</p>
  
  <p><a href="https://i.stack.imgur.com/h8sti.png" rel="nofollow noreferrer">allowed : GET,OPTIONS,PUT.img</a></p>
  
  <p>please let me know where i am missing.</p>
  
  <p>Edit : Source code :</p>
  
  <pre><code>import java.util.List;
  
  import javax.ws.rs.Consumes;
  import javax.ws.rs.DELETE;
  import javax.ws.rs.GET;
  import javax.ws.rs.POST;
  import javax.ws.rs.PUT;
  import javax.ws.rs.Path;
  import javax.ws.rs.PathParam;
  import javax.ws.rs.Produces;
  import javax.ws.rs.core.MediaType;
  
  import org.koushik.javabrains.messenger.model.Message;
  import org.koushik.javabrains.messenger.service.MessageService;
  
  
  
  @Path("/messages")
  public class MessageResource {
      MessageService messageService = new MessageService();
      @GET
      @Produces(MediaType.APPLICATION_JSON)
      public List&lt;Message&gt; getMessages(){
          System.out.println("Hello There");
          List&lt;Message&gt; returnedList = messageService.getAllMessages();
          System.out.println(returnedList);
          return returnedList;
      }
      @GET
      @Path("/{messageId}")
      @Produces(MediaType.APPLICATION_JSON)
      public Message getMessage(@PathParam("messageId") long messageId){
  
          System.out.println("Message returned");
          return messageService.getMessage(messageId);
  
      }
  
      @POST
      @Produces(MediaType.APPLICATION_JSON)
      public Message addMessage(Message message){
          return messageService.addMessage(message);
      }
  
      @PUT
      @Path("/{messageId}")
      @Produces(MediaType.APPLICATION_JSON)
      @Consumes(MediaType.APPLICATION_JSON)
      public Message updateMessage(@PathParam("messageId") long id , Message message){
          message.setId(id);
          return messageService.updateMessage(message);
      }
  
      @DELETE
      @Path("/messageId")
      @Produces(MediaType.APPLICATION_JSON)
      public void deleteMessage(@PathParam("messageId") long id){
          System.out.println("Hello There");
          messageService.removeMessage(id);
      }
  }
  
  
  
  
  
  
  package org.koushik.javabrains.messenger.service;
  
  import java.util.ArrayList;
  import java.util.List;
  import java.util.Map;
  
  import org.koushik.javabrains.messenger.database.DatabaseClass;
  import org.koushik.javabrains.messenger.model.Message;
  
  public class MessageService {
  
      private Map&lt;Long , Message&gt; messages = DatabaseClass.getMessages();
  
      public MessageService(){
  
          messages.put(1L, new Message(1, "Hello World" , "koushik"));
          messages.put(2L, new Message(2, "Hello Jersey" , "Koushik"));
  
      }
  
      public List&lt;Message&gt; getAllMessages(){
  
          return new ArrayList&lt;Message&gt;(messages.values());
      }
  
      public Message getMessage(long id){
          Message m = messages.get(id);
          System.out.println("Value of message "+m);
          return m;
      }
  
      public Message addMessage(Message message){
  
          message.setId(messages.size()+1);
          messages.put(message.getId(), message);
          return message;
      }
  
      public Message updateMessage(Message message){
  
          if(message.getId() &lt;=0){
              return null;
          }
          messages.put(message.getId(), message);
          return message;
      }
  
      public Message removeMessage(long id){
          return messages.remove(id);
      }
  }
  
  
  
  
  
  
  package org.koushik.javabrains.messenger.database;
  
  import java.util.HashMap;
  import java.util.Map;
  
  import org.koushik.javabrains.messenger.model.Message;
  import org.koushik.javabrains.messenger.model.Profile;
  
  public class DatabaseClass {
  
      private static Map&lt;Long , Message&gt; messages = new HashMap();
  
      private static Map&lt;String , Profile&gt; profiles = new HashMap();
  
      public static Map&lt;Long , Message&gt; getMessages() {
  
          return messages;
      }
  
      public static Map&lt;String, Profile&gt; getProfiles() {
          return profiles;
      }
  
  }
  </code></pre>
  
  <p>except delete other requests are working fine.
  on sending DELETE the server is returning HTTP -405 method not allowed.</p>
  
  <p>also on sending delete request then in the header values postman is showing 
  allow →GET,OPTIONS,PUT</p>
  
  <p>Thanks</p>