diff --git a/spring-web-modules/pom.xml b/spring-web-modules/pom.xml index 62be6fbb3c..a676a86d80 100644 --- a/spring-web-modules/pom.xml +++ b/spring-web-modules/pom.xml @@ -34,6 +34,7 @@ spring-rest-angular spring-rest-http spring-rest-http-2 + spring-rest-http-3 spring-rest-query-language spring-rest-shell spring-rest-simple diff --git a/spring-web-modules/spring-rest-http-2/README.md b/spring-web-modules/spring-rest-http-2/README.md index 2c1b1f76f7..cf9ca17077 100644 --- a/spring-web-modules/spring-rest-http-2/README.md +++ b/spring-web-modules/spring-rest-http-2/README.md @@ -14,4 +14,4 @@ The "REST With Spring 2" Classes: http://bit.ly/restwithspring - [Get All Endpoints in Spring Boot](https://www.baeldung.com/spring-boot-get-all-endpoints) - [HTTP PUT vs. POST in REST API](https://www.baeldung.com/rest-http-put-vs-post) - [415 Unsupported MediaType in Spring Application](https://www.baeldung.com/spring-415-unsupported-mediatype) -- More articles: [[<-- prev]](../spring-rest-http) +- More articles: [[next -->]](../spring-rest-http-3) diff --git a/spring-web-modules/spring-rest-http-3/README.md b/spring-web-modules/spring-rest-http-3/README.md new file mode 100644 index 0000000000..062f8a86e2 --- /dev/null +++ b/spring-web-modules/spring-rest-http-3/README.md @@ -0,0 +1,10 @@ +## Spring REST HTTP 3 + +This module contains articles about HTTP in REST APIs with Spring. + +### The Course +The "REST With Spring 3" Classes: http://bit.ly/restwithspring + +### Relevant Articles: + +- More articles: [[<-- prev]](../spring-rest-http) diff --git a/spring-web-modules/spring-rest-http-3/pom.xml b/spring-web-modules/spring-rest-http-3/pom.xml new file mode 100644 index 0000000000..1f2c66e999 --- /dev/null +++ b/spring-web-modules/spring-rest-http-3/pom.xml @@ -0,0 +1,25 @@ + + + 4.0.0 + spring-rest-http-3 + 0.1-SNAPSHOT + spring-rest-http-3 + war + + + com.baeldung + parent-boot-2 + 0.0.1-SNAPSHOT + ../../parent-boot-2 + + + + + org.springframework.boot + spring-boot-starter-web + + + + \ No newline at end of file diff --git a/spring-web-modules/spring-rest-http-3/src/main/java/com/baeldung/SpringBootRest3Application.java b/spring-web-modules/spring-rest-http-3/src/main/java/com/baeldung/SpringBootRest3Application.java new file mode 100644 index 0000000000..3203f6e105 --- /dev/null +++ b/spring-web-modules/spring-rest-http-3/src/main/java/com/baeldung/SpringBootRest3Application.java @@ -0,0 +1,12 @@ +package com.baeldung; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class SpringBootRest3Application { + + public static void main(String[] args) { + SpringApplication.run(SpringBootRest3Application.class, args); + } +} diff --git a/spring-web-modules/spring-rest-http-3/src/main/java/com/baeldung/xwwwformurlencoded/Course.java b/spring-web-modules/spring-rest-http-3/src/main/java/com/baeldung/xwwwformurlencoded/Course.java new file mode 100644 index 0000000000..0ce6f17786 --- /dev/null +++ b/spring-web-modules/spring-rest-http-3/src/main/java/com/baeldung/xwwwformurlencoded/Course.java @@ -0,0 +1,24 @@ +package com.baeldung.xwwwformurlencoded; + +class Course { + + private String name; + private int hours; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public int getHours() { + return hours; + } + + public void setHours(int hours) { + this.hours = hours; + } + +} diff --git a/spring-web-modules/spring-rest-http-3/src/main/java/com/baeldung/xwwwformurlencoded/StudentComplex.java b/spring-web-modules/spring-rest-http-3/src/main/java/com/baeldung/xwwwformurlencoded/StudentComplex.java new file mode 100644 index 0000000000..240d0b38c9 --- /dev/null +++ b/spring-web-modules/spring-rest-http-3/src/main/java/com/baeldung/xwwwformurlencoded/StudentComplex.java @@ -0,0 +1,32 @@ +package com.baeldung.xwwwformurlencoded; + +class StudentComplex { + + private String firstName; + private String lastName; + private Course[] courses; + + public String getFirstName() { + return firstName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + public String getLastName() { + return lastName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } + + public Course[] getCourses() { + return courses; + } + + public void setCourses(Course[] courses) { + this.courses = courses; + } +} diff --git a/spring-web-modules/spring-rest-http-3/src/main/java/com/baeldung/xwwwformurlencoded/StudentController.java b/spring-web-modules/spring-rest-http-3/src/main/java/com/baeldung/xwwwformurlencoded/StudentController.java new file mode 100644 index 0000000000..3e007b9a55 --- /dev/null +++ b/spring-web-modules/spring-rest-http-3/src/main/java/com/baeldung/xwwwformurlencoded/StudentController.java @@ -0,0 +1,24 @@ +package com.baeldung.xwwwformurlencoded; + +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/students") +public class StudentController { + + @PostMapping(path = "/simple", + consumes = { MediaType.APPLICATION_FORM_URLENCODED_VALUE }) + public ResponseEntity createStudentSimple(StudentSimple student) { + return ResponseEntity.ok(student); + } + + @PostMapping(path = "/complex", + consumes = { MediaType.APPLICATION_FORM_URLENCODED_VALUE }) + public ResponseEntity createStudentComplex(StudentComplex student) { + return ResponseEntity.ok(student); + } +} diff --git a/spring-web-modules/spring-rest-http-3/src/main/java/com/baeldung/xwwwformurlencoded/StudentSimple.java b/spring-web-modules/spring-rest-http-3/src/main/java/com/baeldung/xwwwformurlencoded/StudentSimple.java new file mode 100644 index 0000000000..e109000e1e --- /dev/null +++ b/spring-web-modules/spring-rest-http-3/src/main/java/com/baeldung/xwwwformurlencoded/StudentSimple.java @@ -0,0 +1,32 @@ +package com.baeldung.xwwwformurlencoded; + +class StudentSimple { + + private String firstName; + private String lastName; + private String[] courses; + + public String getFirstName() { + return firstName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + public String getLastName() { + return lastName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } + + public String[] getCourses() { + return courses; + } + + public void setCourses(String[] courses) { + this.courses = courses; + } +} diff --git a/spring-web-modules/spring-rest-http-3/src/main/resources/application.properties b/spring-web-modules/spring-rest-http-3/src/main/resources/application.properties new file mode 100644 index 0000000000..e69de29bb2