Skip to content

corbtastik/todos-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

85 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Todos Backing API

A sample Spring Boot app that implement a Todo API.

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) { }

Build

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

Run on PCF

  1. Consider forking this project then clone to dev machine
  2. cd into project
  3. mvnw clean package
  4. modify manifest.yml for your cloudfoundry tastes (custom route perhaps?)
  5. login to PCF (or PWS)
  6. cf push (awwwweee yeah)

Local

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

Run with Remote Debug

java -Xdebug -Xrunjdwp:server=y,transport=dt_socket,address=9111,suspend=n \
  -jar target/todos-api-1.0.0.SNAP.jar

Todo(s) Properties

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

Verify

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"
}

Spring Boot references:

  1. Dependency Management in Spring Boot - exact dependency versions
  2. Spring Boot Dependencies
  3. Spring Boot Starters - this app uses spring-boot-starter-web, spring-boot-starter-actuator and spring-boot-starter-sleuth
  4. 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.
  5. Spring Boot Auto Configuration - @SpringBootApplication or @EnableAutoConfiguration
  6. Externalized Configuration
  7. ConfigurationProperties
  8. @ConfigurationProperties vs @Value
  9. Spring MVC Auto-configuration
  10. Spring Boot Security
  11. Testing Spring Boot Applications
  12. Actuator Endpoints