chapter three

3 Getting Started with Cloud Native Development

 

This chapter covers:

  • Bootstrapping a cloud native project
  • Using an embedded web server
  • Building a RESTful application
  • Testing a RESTful application
  • Automating build and tests with a CI pipeline

In the previous chapter, you familiarized yourself with some basic development principles to build a cloud native app. You also had a first hands-on experience creating a minimal Spring Boot application that you run from Gradle. Then, you turned it into a Docker container, and you finally deployed it to a local Kubernetes cluster. Now, I’ll slow down a bit and dive deeper into cloud native development, guiding you step by step.

You’ll begin your cloud native journey with RESTful services. Cloud native applications, as discussed in chapter 1, are distributed systems. The way components of such a system communicate with each other is of great interest, since it’s the system as a whole that provides value to users. In this chapter, you’ll work with the most used interaction that is based on REST APIs. Many components of a cloud native system are likely to expose an API to provide services to several clients. REST (Representational State Transfer) is the most widely adopted architectural style for web applications to integrate with each other.

3.1  Codebase and dependency management

3.1.1  One codebase, one application

3.1.2  Explicit dependencies declaration with Gradle and Maven

3.2  Working with embedded web servers

3.2.1  Executable jars and embedded servers: ready for the cloud

3.2.2  Request/response for synchronous communication

3.2.3  Configuring embedded Tomcat

3.3  Building a RESTful application with Spring MVC

3.3.1  Business logic: entities and use cases

3.3.2  Implementing a REST API with Spring MVC

3.3.3  Data validation and error handling

3.3.4  Evolving APIs for future requirements

3.4  Testing a RESTful application with Spring

3.4.1  Unit tests with JUnit 5

3.4.2  Integration tests with @SpringBootTest

3.4.3  Integration tests with @WebMvcTest

3.4.4  Integration tests with @JsonTest