티스토리 뷰

Functional Endpoints는 스프링 5.x 버전부터 추가된 기능이다.
기존에 Controller를 기반으로 웹서버를 구성하던 것과는 다르게 Functional Endpoints를 사용하면 HandlerFunction과 RouterFunction를 이용해서 좀 더 함수형 기반으로 웹서버를 구성할 수 있다.
HandlerFunction
HandlerFunction은 요청을 처리하고, 응답을 반환한다.

handle
: ServerRequest를 인자로 받고 ServerResponse를 Mono로 반환하는 추상 메서드
RouterFunction
RouterFunction은 path, method, predicate등으로 handlerFunction과 연결하여 해당 요청이 들어왔을 때, handlerFunction을 반환한다.

route
: ServerRequest를 인자로 받고 HandlerFunction을 Mono로 반환하는 추상 메서드
ServerRequest
ServerRequest는 RouterFunction, HandlerFunction을 지원하기 위해 추가된 request 객체이다. 내부적으로 ServerWebExchange를 포함하고 있기 때문에 ServerHttpRequest와 ServerWebExchange의 메서드들을 대부분 지원한다.
ServerResponse
ServerResponse는 HttpHandler 혹은 WebHandler처럼 처음부터 인자로 주어지는 값이 아니기 때문에, 쉽게 ServerResponse를 만들 수 있는 Builder를 제공한다.
ServerResponseBuilder
ServerResponseBuilder는 header, cookie, allow, lastModified, cacheControl, contentType, bodyValue 등을 변경 가능하다.
RouterFunctionBuilder
RouterFunctionBuilder는 GET, HEAD, POST, PUT, PATCH, DELETE, OPTIONS 등의 method를 지원한다. path로 공통 prefix pattern을 붙일 수 있고, nest로 공통 predicate를 더할 수 있다.
handlerFunction
: 해당 조건을 만족했을 경우 실행할 HandlerFunctionpattern
: handlerFunction을 연결할 path 패턴predicate
: handlerFunction을 연결할 추가 조건
RequestPredicate
AcceptPredicate
: accept 헤더가 인자로 주어진 mediaTypes와 일치하는지 확인한다.ContentTypePredicate
: content-type헤 더가 주어진 mediaTypes와 일치하는지 확인한다.HeadersPredicate
: headers가 조건에 만족 하는지 확인한다.HttpMethodPredicate
: method가 주어진 httpMethods에 포함되는지 확인한다.QueryParamPredicate
: queryParam name의 값이 value와 일치하는지 확인한다.PathPatternPredicate
: path가 pattern에 일치하는지 확인한다.
RouterFunction in Spring

- RouterFunction이 bean으로 등록되면 RouterFunctionMapping을 통해 handlerFunction을 반환한다.
- HandlerFunctionAdapter를 통해서 handlerFunction을 실행하고, ServerResponse를 HandlerResult에 담아서 반환한다.
- ServerResponseResultHandler가 HandlerResult로 render
HandlerFunction을 이용한 mapping과 adapter

ServerResponse로 render

RouterFunction Bean
만약 2개 이상의 RouterFunction이 bean으로 등록되면, bean들을 order로 정렬하고 andOther 연산자로 RouterFunction을 합친 뒤, 합쳐진 RouterFunction으로 RouterFunctionMapping에서 HandlerFunction을 반환한다.

'Spring' 카테고리의 다른 글
[Spring Webflux] Spring Security Reactive (0) | 2024.05.09 |
---|---|
[Spring Webflux] WebClient (0) | 2024.05.08 |
[Spring Webflux] DispatcherHandler (0) | 2024.05.06 |
[Spring Webflux] 컨텍스트 (Context) (0) | 2024.01.28 |
[Spring Webflux] 스케줄러 (Scheduler) (0) | 2024.01.21 |
- Total
- Today
- Yesterday
- 알고리즘
- mysql 8.0
- spring boot
- 파이썬
- 릿코드
- 코틀린
- Algorithm
- leetcode
- 노마드
- 자료구조
- 문자열
- 노마드코더
- 김영한
- Spring
- webflux
- 데이터베이스
- 구현
- Real MySQL
- 인프런
- 스프링부트
- 코테
- kotlin
- 정렬
- 백준
- 그리디
- MySQL
- 스프링
- 리팩토링
- 북클럽
- 스프링 부트
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |