Untitled
unknown
java
2 years ago
1.6 kB
14
Indexable
package org.example;
import okhttp3.*;
import java.io.IOException;
public class BitqueryWebsocketClient {
private static final String BEARER_TOKEN = "---------------------------";
private final OkHttpClient client;
private final MediaType mediaType;
private final RequestBody body;
private final Request request;
public BitqueryWebsocketClient() {
client = new OkHttpClient().newBuilder().build();
mediaType = MediaType.parse("application/json");
body = RequestBody.create(mediaType, "{\"query\":\"query MyQuery {\\n EVM(dataset: combined, network: eth) {\\n Blocks(limit: {count: 2}, orderBy: {descending: Block_Number}) {\\n Block {\\n Time\\n Number\\n }\\n }\\n }\\n}\\n\",\"variables\":\"{}\"}");
request = new Request.Builder()
.url("https://streaming.bitquery.io/graphql")
.method("POST", body)
.header("Authorization", "Bearer " + BEARER_TOKEN)
.header("Content-Type", "application/json")
.build();
}
public void executeRequest() {
try {
Response response = client.newCall(request).execute();
System.out.println(response.body().string());
response.close();
} catch (IOException e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
BitqueryWebsocketClient client = new BitqueryWebsocketClient();
client.executeRequest();
}
}
Editor is loading...
Leave a Comment