A sample Spring Boot app that implement a Todo API.
- Spring Boot for app bits
Todos API works with this UI but can be used by itself. If you're interested in running this app as a backend to the UI then start with this repo.
Domain and core API
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
class Todo implements Serializable {
private String id;
private String title;
private Boolean completed = Boolean.FALSE;
}
@PostMapping("/")
public Todo create(@RequestBody Todo todo) { }
@GetMapping("/{id}")
public Todo retrieve(@PathVariable String id) { }
@PatchMapping("/{id}")
public Todo update(@PathVariable String id, @RequestBody Todo todo) { }
@DeleteMapping("/{id}")
public void delete(@PathVariable String id) { }
This project was created from the Spring Initialzr as a Java 1.8, Maven build project. You can build locally using the maven wrapper (mvnw
).
Tomcat is default
./mvnw clean package
# target/todos-api-1.0.0.SNAP.jar
Build with Jetty
./mvnw clean package -P jetty
# target/todos-api-1.0.0.SNAP.jar
Build with Undertow
./mvnw clean package -P undertow
# target/todos-api-1.0.0.SNAP.jar
- Consider forking this project then clone to dev machine
- cd into project
- mvnw clean package
- modify
manifest.yml
for your cloudfoundry tastes (custom route perhaps?) - login to PCF (or PWS)
- cf push (awwwweee yeah)
You can clone, build, run then access localhost:8080
or change the port.
java -jar ./target/todos-api-1.0.0.SNAP.jar \
--server.port=whatever
java -Xdebug -Xrunjdwp:server=y,transport=dt_socket,address=9111,suspend=n \
-jar target/todos-api-1.0.0.SNAP.jar
TodosProperties
contains a couple application properties.
# limit number of todos to put in map
todos.api.limit=1024
# use 8 char random string for id or 36 (uuid)
todos.ids.tiny-id=true
Once Todo(s) API is running access it directly using cURL or HTTPie to perform CRUD operations.
> http :8080/ title="make bacon pancakes"
HTTP/1.1 200
Content-Type: application/json;charset=UTF-8
{
"completed": false,
"id": "c81d4e2e",
"title": "make bacon pancakes"
}
- Dependency Management in Spring Boot - exact dependency versions
- Spring Boot Dependencies
- Spring Boot Starters - this app uses
spring-boot-starter-web
,spring-boot-starter-actuator
andspring-boot-starter-sleuth
- How to embed Web Servers - for servlet stack web apps use tomcat, jetty, or undertow. For reactive stack web apps use the previous servers or netty.
- Spring Boot Auto Configuration -
@SpringBootApplication or @EnableAutoConfiguration
- Externalized Configuration
- ConfigurationProperties
@ConfigurationProperties vs @Value
- Spring MVC Auto-configuration
- Spring Boot Security
- Testing Spring Boot Applications
- Actuator Endpoints