|
|
@ -590,10 +590,10 @@ RouterFunction<ServerResponse> route = route() |
|
|
|
.path("/person", builder -> builder // <1> |
|
|
|
.path("/person", builder -> builder // <1> |
|
|
|
.GET("/{id}", accept(APPLICATION_JSON), handler::getPerson) |
|
|
|
.GET("/{id}", accept(APPLICATION_JSON), handler::getPerson) |
|
|
|
.GET(accept(APPLICATION_JSON), handler::listPeople) |
|
|
|
.GET(accept(APPLICATION_JSON), handler::listPeople) |
|
|
|
.POST("/person", handler::createPerson)) |
|
|
|
.POST(handler::createPerson)) |
|
|
|
.build(); |
|
|
|
.build(); |
|
|
|
---- |
|
|
|
---- |
|
|
|
<1> Note that second parameter of `path` is a consumer that takes the a router builder. |
|
|
|
<1> Note that second parameter of `path` is a consumer that takes the router builder. |
|
|
|
|
|
|
|
|
|
|
|
[source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"] |
|
|
|
[source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"] |
|
|
|
.Kotlin |
|
|
|
.Kotlin |
|
|
@ -602,7 +602,7 @@ RouterFunction<ServerResponse> route = route() |
|
|
|
"/person".nest { |
|
|
|
"/person".nest { |
|
|
|
GET("/{id}", accept(APPLICATION_JSON), handler::getPerson) |
|
|
|
GET("/{id}", accept(APPLICATION_JSON), handler::getPerson) |
|
|
|
GET(accept(APPLICATION_JSON), handler::listPeople) |
|
|
|
GET(accept(APPLICATION_JSON), handler::listPeople) |
|
|
|
POST("/person", handler::createPerson) |
|
|
|
POST(handler::createPerson) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
---- |
|
|
|
---- |
|
|
@ -620,7 +620,7 @@ We can further improve by using the `nest` method together with `accept`: |
|
|
|
.nest(accept(APPLICATION_JSON), b2 -> b2 |
|
|
|
.nest(accept(APPLICATION_JSON), b2 -> b2 |
|
|
|
.GET("/{id}", handler::getPerson) |
|
|
|
.GET("/{id}", handler::getPerson) |
|
|
|
.GET(handler::listPeople)) |
|
|
|
.GET(handler::listPeople)) |
|
|
|
.POST("/person", handler::createPerson)) |
|
|
|
.POST(handler::createPerson)) |
|
|
|
.build(); |
|
|
|
.build(); |
|
|
|
---- |
|
|
|
---- |
|
|
|
[source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"] |
|
|
|
[source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"] |
|
|
@ -631,7 +631,7 @@ We can further improve by using the `nest` method together with `accept`: |
|
|
|
accept(APPLICATION_JSON).nest { |
|
|
|
accept(APPLICATION_JSON).nest { |
|
|
|
GET("/{id}", handler::getPerson) |
|
|
|
GET("/{id}", handler::getPerson) |
|
|
|
GET(handler::listPeople) |
|
|
|
GET(handler::listPeople) |
|
|
|
POST("/person", handler::createPerson) |
|
|
|
POST(handler::createPerson) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -766,7 +766,7 @@ For instance, consider the following example: |
|
|
|
.before(request -> ServerRequest.from(request) // <1> |
|
|
|
.before(request -> ServerRequest.from(request) // <1> |
|
|
|
.header("X-RequestHeader", "Value") |
|
|
|
.header("X-RequestHeader", "Value") |
|
|
|
.build())) |
|
|
|
.build())) |
|
|
|
.POST("/person", handler::createPerson)) |
|
|
|
.POST(handler::createPerson)) |
|
|
|
.after((request, response) -> logResponse(response)) // <2> |
|
|
|
.after((request, response) -> logResponse(response)) // <2> |
|
|
|
.build(); |
|
|
|
.build(); |
|
|
|
---- |
|
|
|
---- |
|
|
@ -784,7 +784,7 @@ For instance, consider the following example: |
|
|
|
ServerRequest.from(it) |
|
|
|
ServerRequest.from(it) |
|
|
|
.header("X-RequestHeader", "Value").build() |
|
|
|
.header("X-RequestHeader", "Value").build() |
|
|
|
} |
|
|
|
} |
|
|
|
POST("/person", handler::createPerson) |
|
|
|
POST(handler::createPerson) |
|
|
|
after { _, response -> // <2> |
|
|
|
after { _, response -> // <2> |
|
|
|
logResponse(response) |
|
|
|
logResponse(response) |
|
|
|
} |
|
|
|
} |
|
|
@ -815,7 +815,7 @@ The following example shows how to do so: |
|
|
|
.nest(accept(APPLICATION_JSON), b2 -> b2 |
|
|
|
.nest(accept(APPLICATION_JSON), b2 -> b2 |
|
|
|
.GET("/{id}", handler::getPerson) |
|
|
|
.GET("/{id}", handler::getPerson) |
|
|
|
.GET(handler::listPeople)) |
|
|
|
.GET(handler::listPeople)) |
|
|
|
.POST("/person", handler::createPerson)) |
|
|
|
.POST(handler::createPerson)) |
|
|
|
.filter((request, next) -> { |
|
|
|
.filter((request, next) -> { |
|
|
|
if (securityManager.allowAccessTo(request.path())) { |
|
|
|
if (securityManager.allowAccessTo(request.path())) { |
|
|
|
return next.handle(request); |
|
|
|
return next.handle(request); |
|
|
@ -835,7 +835,7 @@ The following example shows how to do so: |
|
|
|
("/person" and accept(APPLICATION_JSON)).nest { |
|
|
|
("/person" and accept(APPLICATION_JSON)).nest { |
|
|
|
GET("/{id}", handler::getPerson) |
|
|
|
GET("/{id}", handler::getPerson) |
|
|
|
GET("", handler::listPeople) |
|
|
|
GET("", handler::listPeople) |
|
|
|
POST("/person", handler::createPerson) |
|
|
|
POST(handler::createPerson) |
|
|
|
filter { request, next -> |
|
|
|
filter { request, next -> |
|
|
|
if (securityManager.allowAccessTo(request.path())) { |
|
|
|
if (securityManager.allowAccessTo(request.path())) { |
|
|
|
next(request) |
|
|
|
next(request) |
|
|
|