Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save moelholm/2e0346792c891dcccf8d2450d49680e4 to your computer and use it in GitHub Desktop.
Save moelholm/2e0346792c891dcccf8d2450d49680e4 to your computer and use it in GitHub Desktop.
import org.springframework.http.MediaType;
import org.springframework.http.client.reactive.ReactorClientHttpConnector;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.reactive.WebClient;
import reactor.core.publisher.Mono;
import static org.springframework.web.client.reactive.ClientWebRequestBuilders.get;
import static org.springframework.web.client.reactive.ResponseExtractors.body;
@RestController
public class ReactiveController {
@RequestMapping("/reactive-controller")
public Mono<String> sayHello() {
WebClient reactiveHttpClient = new WebClient(new ReactorClientHttpConnector());
return reactiveHttpClient
.perform(get("http://localhost:8080/traditional-controller").accept(MediaType.TEXT_PLAIN))
.extract(body(String.class));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment