Skip to content

Commit

Permalink
Added the customary hello world endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
dilipkrish committed Jun 19, 2020
1 parent f81ffd0 commit 890b44b
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,51 @@

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.reactive.function.BodyInserters;
import org.springframework.web.reactive.function.server.RequestPredicates;
import org.springframework.web.reactive.function.server.RouterFunction;
import org.springframework.web.reactive.function.server.RouterFunctions;
import org.springframework.web.reactive.function.server.ServerRequest;
import org.springframework.web.reactive.function.server.ServerResponse;
import reactor.core.publisher.Mono;

@SpringBootApplication
public class BootWebfluxApplication {

public static void main(String[] args) {
SpringApplication.run(BootWebfluxApplication.class, args);
}
public static void main(String[] args) {
SpringApplication.run(BootWebfluxApplication.class, args);
}

@RestController
@RequestMapping("/functional-hello")
public static class FunctionalHelloWorldController {
@GetMapping
public Mono<String> hello() {
return Mono.fromSupplier(() -> "Hello SpringFox!");
}
}

@Bean
public RouterFunction<ServerResponse> route(GreetingHandler greetingHandler) {
return RouterFunctions
.route(RequestPredicates.GET("/hello")
.and(RequestPredicates.accept(MediaType.TEXT_PLAIN)),
greetingHandler::hello);
}

@Component
public static class GreetingHandler {

public Mono<ServerResponse> hello(ServerRequest request) {
return ServerResponse.ok()
.contentType(MediaType.TEXT_PLAIN)
.body(BodyInserters.fromValue("Hello, SpringFox!"));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,24 @@

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@SpringBootApplication
public class BootWebmvcApplication {

public static void main(String[] args) {
SpringApplication.run(BootWebmvcApplication.class, args);
}
public static void main(String[] args) {
SpringApplication.run(BootWebmvcApplication.class, args);
}

@RestController
@RequestMapping("/hello")
public static class HelloWorldController {
@GetMapping
public ResponseEntity<String> hello() {
return ResponseEntity.ok("Hello SpringFox!");
}
}
}

0 comments on commit 890b44b

Please sign in to comment.