I am pretty new in RESTful web services and I have the following doubt. I am working on a Spring MVC application (but this is not so important because my doubt is more related to REST concept).
I have this domain class:
@Entity
@Table(name = "accomodation_media")
public class AccomodationMedia {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private Long id;
//@Column(name = "accomodation_fk")
//private Long idAccomodation;
@ManyToOne
@JoinColumn(name = "accomodation_fk", nullable = false)
private Accomodation accomodation;
@Column(name = "is_master")
private boolean isMaster;
@Lob
@Column(name = "media")
private byte[] media;
private String description;
private Date time_stamp;
.................................................................
.................................................................
GETTER AND SETTER METHODS
.................................................................
.................................................................
}
That represent records into the room_media table of my database.
Then I have a controller method that handle HTTP Requesto toward the URL: /Accomodation/{accomodationId}/accomodationMedia/{mediaId}.
Something like this:
@RequestMapping(value = "/{accomodationId}/accomodationMedia/{newMasterImgId}", method = RequestMethod.XXXX)
public ResponseEntity<String> changeMasterImg(@PathVariable Long accomodationId,
@PathVariable Long newMasterImgId) throws Exception {
accomodationMediaService.changeMasterImg(accomodationId, newMasterImgId);
return ResponseEntity.ok("Master Image cambiata");
}
This method call the changeMasterImg() that basically retrieve an AccomodationMedia instance from the database, change the value of the isMaster field and update it.
So basically this method handle a partial update because it now insert a brand new object but retrieve an object, modify it and update it.
So my doubts are:
1) According to RESTful standard have I to use POST as request to update the AccomodationMedia resource? I have read that maybe I can also use PATCH for a partial update. What is the difference between the use of POST and PATCH Http Method? What is the best in this case?
2) What kind of status code response have I to return in case of successful update? Here: Best practice for partial updates in a RESTful service
It say 303 but way 303 that should be a redirectional message and not something like 200 that means that the operation is ok?