API
Using RapiAPI and creating a Web Service
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://contextualwebsearch-websearch-v1.p.rapidapi.com/api/Search/ImageSearchAPI?q=dream%20face%20reveal&pageNumber=1&pageSize=10&autoCorrect=true"))
.header("X-RapidAPI-Key", "ba3cd3168dmsh90f3dc264426f1bp1aa7f3jsne8dc8f45e66c")
.header("X-RapidAPI-Host", "contextualwebsearch-websearch-v1.p.rapidapi.com")
.method("GET", HttpRequest.BodyPublishers.noBody())
.build();
HttpResponse<String> response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
function ApiRequest() {
const http = require("https");
const options = {
"method": "GET",
"hostname": "contextualwebsearch-websearch-v1.p.rapidapi.com",
"port": null,
"path": "/api/Search/ImageSearchAPI?q=taylor%20swift&pageNumber=1&pageSize=10&autoCorrect=true",
"headers": {
"X-RapidAPI-Key": "ba3cd3168dmsh90f3dc264426f1bp1aa7f3jsne8dc8f45e66c",
"X-RapidAPI-Host": "contextualwebsearch-websearch-v1.p.rapidapi.com",
"useQueryString": true
}
};
const req = http.request(options, function (res) {
let str = "";
res.on("data", function (chunk) {
str += chunk;
});
res.on("end", function () {
parsedData = JSON.parse(str);
// print first hit in data
console.log(parsedData['value'][0])
});
});
req.end();
}
ApiRequest();