Building Microservices with Spring Boot and Docker
Part 3: REST with Spring MVC
Evolution of Systems communication
History
-
Remote Procedure Calls (RPC, 1976)
- CORBA (OMG)
- Remote Method Invocation (RMI, Java)
- DCOM (Microsoft)
- XML-RPC (1998) & SOAP (1999)
- REST (theory: 2000, practical usage: 2014)
SOAP Example: XML Schema/WSDL

SOAP Example: XML Request

REST...
REST is a architectural style for distributed systems
"Representational State Transfer"
people often mean „RESTful HTTP“...
...when they say "REST"
Reusing the web´s infrastructure
- HTTP clients (Browsers)
- webservers
- parsers
- caching
- loadbalancing
- ssl
- ...
URI
URI = a Resources´ path and name, no Operation names!
In contrast to the RPC Styles!
Resources, Representations & Operations
Resources (URIs), http://api.devopenspace.de/users/1234
Representations and JSON, PDF, XML, HTML, ...
Operations on them GET, PUT, POST, DELETE, ...

HTTP verbs
HTTP Statuscodes
Code | What it means |
---|---|
1xx |
information |
2xx | everything´s good |
3xx | go somewhere else |
4xx | the others screwed up |
5xx | we messed up |


REST Clients
curl
Easiest tool to transfer data via REST!
...and it´s available nearly everywhere

-i include protocol headers in the output (H/F)
-k Ignore insecure certs
-X the HTTP method
-H add headers
Postman
Best REST GUI client, Chrome based

Object Mapping
JSON Object Mapping


Jackson internally...
JSON-2-Java: User user = mapper.readValue(new File("user.json"), User.class);
Java-2-JSON: String json = mapper.writeValueAsString(user);
REST in Spring (Boot)
REST in Spring



Requests...


Requests with URI parametes...

Responses...


Testing with Spring

Testing with Spring


Testing with Spring


Testing with Spring


Let´s do it!
Copy of Part 3: REST with Spring MVC
By jonashackt
Copy of Part 3: REST with Spring MVC
Building Microservices with Spring Boot and Docker
- 989