title: Curl command not working (Spring Boot project)
body: <p>I want to display all messages from MySQL database that start with id = 275. I wrote a curl request I don’t know. Maybe the request was written incorrectly. Maybe the query syntax made a mistake - </p>
  
  <pre><code>curl -H "Content-Type: application/json" -d "{ \"messageId\": \"275\" }" localhost:8080/api/unread
  </code></pre>
  
  <p>But when I run this curl request through the command line, it shows an error.</p>
  
  <pre><code>{"timestamp":"2020-01-06T03:13:07.899+0000","status":405,"error":"Method Not Allowed","message":"Request method 'POST' not supported","trace":"org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'POST' not supported\r\n\tat org.springframework.web.servlet.mvc.method.RequestMappingInfoHandlerMapping.handleNoMatch(
  </code></pre>
  
  <p>My code
  Input Message class</p>
  
  <pre><code>public class InputMessage {
  
      private long messageId;
  
      public InputMessage(long messageId) {
          this.messageId = messageId;
      }
  
      public InputMessage() {
      }
  
      public long getMessageId() {
          return messageId;
      }
  
      public void setMessageId(long messageId) {
          this.messageId = messageId;
      }
  }
  </code></pre>
  
  <p>RestController</p>
  
  <pre><code>public class RestController {
  
      @Autowired
      TimerTask timerTask;
  
      @Resource
      private final MessageService messageService;
  
      public RestController(MessageService messageService) {
          this.messageService = messageService;
      }
  
      @PostMapping("/api/save")
      public MessageStatus saveMessage(@RequestBody Message chatMessage) {
          return messageService.add(chatMessage);
      }
  
      @GetMapping("/api/last")
      public String getLasts() {
          return new Gson().toJson(messageService.getLast());
      }
  
      @GetMapping("/api/unread")
      public void getUnreadMessages() {
  
          timerTask.run();
      }
  
      @GetMapping("/api/unread/byid")
      public List&lt;Message&gt; getUnreadById(@RequestBody InputMessage message) {
          return messageService.getUnreadById(message);
      }
  </code></pre>
  
  <p>Message Service Impl</p>
  
  <pre><code>public class MessageServiceImpl implements MessageService {
      private final MessageRepository repository;
      private final PageRequest lastRequest;
  
      private List&lt;Long&gt; chekedMessages = new ArrayList&lt;&gt;();
  
  
      @Autowired
      public MessageServiceImpl(MessageRepository repository) {
          this.repository = repository;
          lastRequest = new PageRequest(0, 10, Sort.Direction.DESC, "id");
      }
  
      @Override
      public MessageStatus add(@RequestBody  Message message) {
          if(message == null) {
              System.out.println("Пришел пустой запрос на сохранение данных");
  
          }
          MessageStatus status = new MessageStatus();
          try {
              repository.save(message);
              status.setMessage("Сообщение успешно сохранено");
          }
          catch (Exception e) {
              status.setMessage("Во время сохранения сообщения произошла ошибка");
          }
          return status;
      }
  
      @Override
      public List&lt;Message&gt; getAllMessages() {
          return repository.findAll();
      }
  
      @Override
      public List&lt;Message&gt; getLast() {
          List&lt;Message&gt; result = repository.findAll(lastRequest).getContent();
  
          return result.stream()
                  .sorted(Comparator.comparingLong(Message::getId))
                  .collect(Collectors.toList());
      }
  
      @Override
      public List&lt;Message&gt; getUnreadById(InputMessage message) {
           return repository.getUnreadById(message.getMessageId());
      }
  
  
  
      @Override
      public String getUnreadMessages() {
          List&lt;Message&gt; out = new ArrayList&lt;&gt;();
          List&lt;Message&gt; unchekedMessages = repository.findAll();
          for (Message message: unchekedMessages) {
              if (!chekedMessages.contains(message.getId())) {
                  chekedMessages.add(message.getId());
                  out.add(message);
              }
          }
          return new Gson().toJson(out);
      }
  
      @Override
      public void updateMessage(long id, Message message) {
          if (repository.findById(id).isPresent()) {
              message.setId(id);
              repository.save(message);
          }
      }
  </code></pre>
  
  <p>github 
  <a href="https://github.com/fallen3019/vaadin-chat" rel="nofollow noreferrer">https://github.com/fallen3019/vaadin-chat</a></p>