Example usage for org.springframework.web.reactive.function.server ServerRequest pathVariable

List of usage examples for org.springframework.web.reactive.function.server ServerRequest pathVariable

Introduction

In this page you can find the example usage for org.springframework.web.reactive.function.server ServerRequest pathVariable.

Prototype

default String pathVariable(String name) 

Source Link

Document

Get the path variable with the given name, if present.

Usage

From source file:top.zhacker.ms.reactor.spring.function.handler.PersonHandler.java

public Mono<ServerResponse> getPerson(ServerRequest request) {
    int personId = Integer.valueOf(request.pathVariable("id"));
    Mono<ServerResponse> notFound = ServerResponse.notFound().build();
    Mono<Person> personMono = this.repository.getPerson(personId);
    return personMono
            .flatMap(person -> ServerResponse.ok().contentType(APPLICATION_JSON).body(fromObject(person)))
            .switchIfEmpty(notFound);//from   ww  w  . j  av  a2  s .c  o  m
}

From source file:com.example.talk.TalkEndpoint.java

Mono<ServerResponse> getTalkRoom(final ServerRequest serverRequest) {
    final long talkId = Long.parseLong(serverRequest.pathVariable("talkId"));
    final Mono<TalkRoom> talkRoom = talkRoomRepository.getTalkRoomByTalkRoomId(talkId);
    return talkRoom.flatMap(tr -> ServerResponse.ok().contentType(MediaType.APPLICATION_JSON)
            .body(Mono.just(tr), TalkRoom.class)).switchIfEmpty(ServerResponse.notFound().build());
}