Upgrade to Pro — share decks privately, control downloads, hide ads and more …

New in Spring 5: Functional Web Framework

New in Spring 5: Functional Web Framework

Slides from Dutch Spring Meetup

Avatar for Arjen Poutsma

Arjen Poutsma

October 27, 2016
Tweet

More Decks by Arjen Poutsma

Other Decks in Programming

Transcript

  1. About Arjen • Twenty years of experience in Enterprise Software

    Development • Joined SpringSource in 2005 • Development lead of Spring Web Services, Spring MVC, Spring Scala • Working on Spring 5
  2. ...but there are downsides • “Magic” • No clear link

    between annotation and behavior • Runtime handling • Reflection
  3. Design Goals • Functional Style • java.util.function • java.util.stream •

    More library; less framework • Explicit • Customizable • No reflection
  4. Immutability • No change after construction • Builders • Thread-safety

    •e.g. String •toUpperCase() •StringBuilder
  5. First-class Functions • Functions as first-class citizens • Functions as

    arguments • Functions as return value • Reusability •e.g. String •indexOf(char) vs indexOf(Predicate<Char>)
  6. Pure Functions • Same result given same arguments • No

    Limit side effects • Application boundaries • Testability • Cacheability • Parallelization
  7. ServerRequest • Similar to RequestEntity • Immutable • Headers •

    Optional<MediaType> contentType() • List<String> header(String) • Body • Mono<T> bodyToMono(Class<T>)
  8. ServerResponse • Similar to ResponseEntity • Immutable w/ Builder •

    Headers • lastModified(ZonedDateTime) • header(String, String...) • Body • body(Publisher<T>, Class<T>)
  9. Running a Server • Convert RouterFunction to HttpHandler • HttpHandler

    runs • Reactor Netty • RxNetty • Servlet 3.1 • Undertow
  10. Summary • Handler functions handle request by returning a response

    • Router functions route to handler functions • Router functions can be filtered by filter functions • Router functions can be run in a reactive web runtime