Custom Media Types for REST (#918)
* Custom Media Types for REST * add test, add DTO, remove example of API versioning to make example simpler * client accept only that custom-media type * remove not needed new_line * leave custom media type on class level
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
package org.baeldung.web.controller.mediatypes;
|
||||
|
||||
|
||||
import org.baeldung.web.dto.BaeldungItem;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@RequestMapping(value = "/", produces = "application/vnd.baeldung.api.v1+json",
|
||||
consumes = "application/vnd.baeldung.api.v1+json")
|
||||
public class CustomMediaTypeController {
|
||||
|
||||
@RequestMapping(value = "/public/api/endpoint", produces = "application/vnd.baeldung.api.v1+json",
|
||||
consumes = "application/vnd.baeldung.api.v1+json")
|
||||
public @ResponseBody ResponseEntity<BaeldungItem> getItem() {
|
||||
return new ResponseEntity<>(new BaeldungItem("itemId1"), HttpStatus.OK);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package org.baeldung.web.dto;
|
||||
|
||||
|
||||
public class BaeldungItem {
|
||||
private final String itemId;
|
||||
|
||||
public BaeldungItem(String itemId) {
|
||||
this.itemId = itemId;
|
||||
}
|
||||
|
||||
public String getItemId() {
|
||||
return itemId;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user