Created
November 6, 2026 14:28
-
-
Save janedbal/8c4dfc7d5e95ff5a76e568afdc0ff467 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.example; | |
| import com.fasterxml.jackson.databind.json.JsonMapper; | |
| import java.net.*; | |
| import java.net.http.HttpClient; | |
| import java.net.http.HttpRequest; | |
| import java.net.http.HttpResponse.BodyHandlers; | |
| public class CompanyFinder | |
| { | |
| private static final String ENDPOINT = "https://some.api"; | |
| public String getCompanyName(String identification) throws Exception | |
| { | |
| var httpClient = HttpClient.newHttpClient(); | |
| var request = HttpRequest.newBuilder() | |
| .uri(new URI(ENDPOINT + "/company-info.json?identification=" + identification)) | |
| .build(); | |
| var httpResponse = httpClient.send(request, BodyHandlers.ofString()); | |
| var body = new JsonMapper().readValue(httpResponse.body(), ApiResponse.class); | |
| if (body.error() != null) { | |
| return null; | |
| } | |
| return body.companyFound() | |
| ? body.companyData().companyName() | |
| : null; | |
| } | |
| record ApiResponse(String error, boolean companyFound, CompanyData companyData) | |
| { | |
| record CompanyData(String companyName) | |
| { | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment