By default, the HAPI FHIR client uses the Apache HTTP Client (HC) as it's underlying HTTP provider. HC is a very powerful and efficient provider, so it is generally a good choice.

It can be replaced however by providing an alternate implementation of IRestfulClientFactory to the FhirContext.


If you are using HAPI FHIR's client in an environment where other JAX-RS clients are being used, you may want to use the JAX-RS provider instead of the Apache HC provider.

Using this provider is as simple as creating an instance and providing it to the context:

// Create a client
FhirContext ctx = FhirContext.forDstu2();

// Create an instance of the JAX RS client factory and
// set it on the context
JaxRsRestfulClientFactory clientFactory = new JaxRsRestfulClientFactory(ctx);

// This client uses JAX-RS!
IGenericClient client = ctx.newRestfulGenericClient("");

Note that this provider is defined in the JAX-RS Server module, so you need to add the following dependency to your project in order for this to work: