Skip to content

Instantly share code, notes, and snippets.

@parameshjava
Created September 7, 2021 16:22
Show Gist options
  • Save parameshjava/d1a29796344261390553faee2ac69945 to your computer and use it in GitHub Desktop.
Save parameshjava/d1a29796344261390553faee2ac69945 to your computer and use it in GitHub Desktop.
StackOverflow_Question_69089296
plugins {
id 'java'
id 'maven-publish'
}
repositories {
mavenLocal()
maven {
url = uri('http://repo1.uhc.com/artifactory/libs-snapshots')
}
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-webflux:2.5.4'
implementation 'io.projectreactor:reactor-core:3.4.9'
implementation 'org.springframework.boot:spring-boot-starter-reactor-netty:2.5.4'
implementation 'io.projectreactor.netty:reactor-netty-core:1.0.10'
implementation 'io.projectreactor.netty:reactor-netty-http:1.0.10'
implementation 'org.springframework:spring-webflux:5.3.9'
}
group = 'com.sample'
version = '0.0.1-SNAPSHOT'
description = 'sample-project'
java.sourceCompatibility = JavaVersion.VERSION_11
publishing {
publications {
maven(MavenPublication) {
from(components.java)
}
}
}
---------------------------------------------
{
"args": {},
"data": "",
"files": {},
"form": {},
"headers": {
"Accept": "*/*",
"Accept-Encoding": "gzip",
"Cache-Control": "max-stale=0",
"Content-Type": "application/json",
"Host": "httpbin.org",
"If-Modified-Since": "Tue, 07 Sep 2021 14:42:52 GMT",
"User-Agent": "ReactorNetty/1.0.10",
"X-Amzn-Trace-Id": "Root=1-61377be8-19db88030eb9948d1dd6f632",
"X-Bluecoat-Via": "d33001d0ac968777"
},
"json": null,
"method": "GET",
"origin": "198.203.175.175",
"url": "http://httpbin.org/anything"
}
---------------------------------------------
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.web.reactive.function.client.WebClient;
public class SampleWebClient {
public static void main(String[] args) {
WebClient webClient = WebClient.builder().baseUrl("http://httpbin.org")
.defaultHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE).build();
try {
String response = webClient.get().uri("/anything").exchange().block().bodyToMono(String.class).block();
System.out.println("---------------------------------------------");
System.out.println(response);
System.out.println("---------------------------------------------");
} catch (Exception e) {
e.printStackTrace();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment