Java Apache httpclient authentication for IBM FHIR
Dr. Viktor Walter-Tscharf1 MIN. LESEZEIT
Just a few days ago I had the task of implementing or adding the basic authentication for the IBM FHIR server that was already implemented in my backend. For security reasons an extra basic authentication was added. Therefore I needed to add this into my backend is well.
Originally the URL was:
https://Host:Port/fhir-server/api/v4
Changes, which I made:
https://username:password@host:port/fhir-server/api/v4
Thought the adding of fhiruser:prosituser@ to each request URL of the httpclient the authentification is implemented.
Java example:
String tmpUrl = "https://admin:pA$word@192.168.1.247:9443/fhir-server/api/v4/Patient?_format=json&_pretty=true";
HttpGet request = new HttpGet(tmpUrl);
HttpResponse response = httpClient.execute(request);
result = EntityUtils.toString(response.getEntity());
System.out.println(result);
CURL example:
curl --location --request GET 'https://admin:pA$word@192.168.1.247:9443/fhir-server/api/v4/Patient?_format=json&_pretty=true'
The last part “Patient?_format=json&_pretty=true” just tells the IBM Server to return the Patients and formats it as json.


