-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathImageProfile.java
More file actions
20 lines (19 loc) · 1.01 KB
/
Copy pathImageProfile.java
File metadata and controls
20 lines (19 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
public class ImageProfile {
public static void main(String[] args) throws Exception {
String apiKey = System.getenv("AVATARLOOKUP_API_KEY");
if (apiKey == null) throw new IllegalStateException("Set AVATARLOOKUP_API_KEY");
String body = "{\"product\":\"image_profile\",\"image_url\":\"https://example.com/portrait.jpg\"}";
HttpRequest request = HttpRequest.newBuilder(URI.create("https://avatarlookup.com/api/v1/image/profile"))
.header("X-API-Key", apiKey)
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(body))
.build();
HttpResponse<String> response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString());
if (response.statusCode() >= 300) throw new IllegalStateException(response.body());
System.out.println(response.body());
}
}