title: Adding links to POST/PUT/PATCH operations in REST Web Controllers
body: <p>I have a Java-written Web API wherein I have web controllers handling HTTP requests. I'm trying to implement a RESTful architecture with HATEOAS, using Spring Boot. When adding HATEOAS links in methods I can easily add links for GET/DELETE requests, but I'm having trouble with POST/PUT/PATCH requests, mostly because those require me to supply a body of the thing I want to post, usually in JSON format. I've been googling for a while and I can't find out how to do it.</p>
  
  <p>Here's how I'm adding links to GET / DELETE operations.</p>
  
  <pre class="lang-java prettyprint-override"><code>    /**
       * Shows all the Rooms present in the database.
       *
       * @return OK status and a list of Room Minimal DTO.
       */
      @GetMapping(path = "/", produces = MediaType.APPLICATION_JSON_VALUE)
      public ResponseEntity&lt;Object&gt; getRooms() {
          List&lt;RoomDTOMinimal&gt; roomDTOList = roomRepository.getAllDTOWebInformation();
          for (RoomDTOMinimal r : roomDTOList) {
              if (userService.getUsernameFromToken().equals("ADMIN")) {
                  Link roomSensors = linkTo(methodOn(RoomsWebController.class).getSensors(r.getName())).withRel("Get Room" +
                          "Sensors");
                  Link deleteRoom = linkTo(methodOn(RoomsWebController.class).deleteRoom(r)).withRel("Delete this Room");
                  r.add(roomSensors);
                  r.add(deleteRoom);
              } else if (userService.getUsernameFromToken().equals("REGULAR_USER")) {
                  Link roomTemp = linkTo(methodOn(RoomsWebController.class).getCurrentRoomTemperature(r.getName())).
                          withRel("Get Room Temperature");
                  r.add(roomTemp);
              }
          }
          return new ResponseEntity&lt;&gt;(roomDTOList, HttpStatus.OK);
      }
  </code></pre>
  
  <p>I want to add a Link to an "editRoom" request, something like:</p>
  
  <pre class="lang-java prettyprint-override"><code>                Link editRoom = linkTo(methodOn(RoomsWebController.class).configureRoom(r.getName(),  WHAT GOES HERE???).withSelfRel();
  </code></pre>
  
  <p>But configureRoom takes in the roomName and a roomDTO in its signature. RoomDTO is a @RequestBody, so I can't give it to the Link. How should I add the link to the objects in a way that then allows me to call on that method? </p>
  
  <p>I'd like to have something like:</p>
  
  <p>ROOM | Delete | Edit</p>
  
  <p>On the client side, where if I click DELETE the room is deleted, and if I click Edit the client side expands, with text boxes, allowing me to insert the required parameters to edit the room. I have the client-side code implemented for the Edit function, with appropriate front-end; but I can't link to it on the server-side without already providing data that should come later, from the user input. What's the best way to do this?</p>