Learn how to interact with the HAPI FHIR REST API.
The FHIR R4 API is available at:
http://localhost:8080/fhir
View the server's capability statement:
curl http://localhost:8080/fhir/metadataThis returns a CapabilityStatement resource describing supported features.
List all patients:
curl http://localhost:8080/fhir/PatientSearch with parameters:
# Find patients named "Smith"
curl "http://localhost:8080/fhir/Patient?family=Smith"
# Find observations with a specific code
curl "http://localhost:8080/fhir/Observation?code=http://loinc.org|55284-4"curl http://localhost:8080/fhir/Patient/123curl -X POST http://localhost:8080/fhir/Patient \
-H "Content-Type: application/fhir+json" \
-d '{
"resourceType": "Patient",
"name": [{"family": "Smith", "given": ["John"]}],
"birthDate": "1980-01-15"
}'curl -X PUT http://localhost:8080/fhir/Patient/123 \
-H "Content-Type: application/fhir+json" \
-d '{
"resourceType": "Patient",
"id": "123",
"name": [{"family": "Smith", "given": ["John", "Robert"]}],
"birthDate": "1980-01-15"
}'curl -X DELETE http://localhost:8080/fhir/Patient/123| Parameter | Description | Example |
|---|---|---|
_id |
Resource ID | ?_id=123 |
_lastUpdated |
Last update time | ?_lastUpdated=gt2023-01-01 |
_count |
Results per page | ?_count=50 |
_sort |
Sort order | ?_sort=-_lastUpdated |
_summary |
Summary mode | ?_summary=count |
| Parameter | Description | Example |
|---|---|---|
family |
Family name | ?family=Smith |
given |
Given name | ?given=John |
birthdate |
Birth date | ?birthdate=1980-01-15 |
identifier |
Identifier | ?identifier=12345 |
# Find observations for a specific patient
curl "http://localhost:8080/fhir/Observation?subject=Patient/123"
# Include referenced resources
curl "http://localhost:8080/fhir/Observation?_include=Observation:subject"curl http://localhost:8080/fhir/Patient \
-H "Accept: application/fhir+json"curl http://localhost:8080/fhir/Patient \
-H "Accept: application/fhir+xml"Add _pretty=true to format the response:
curl "http://localhost:8080/fhir/Patient?_pretty=true"curl -X POST http://localhost:8080/fhir \
-H "Content-Type: application/fhir+json" \
-d '{
"resourceType": "Bundle",
"type": "transaction",
"entry": [
{
"resource": {
"resourceType": "Patient",
"name": [{"family": "Doe"}]
},
"request": {
"method": "POST",
"url": "Patient"
}
}
]
}'# Initiate export
curl -X GET "http://localhost:8080/fhir/\$export" \
-H "Accept: application/fhir+json" \
-H "Prefer: respond-async"HAPI FHIR includes a web interface for browsing and testing:
- Open http://localhost:8080
- Use the search forms to query resources
- View and edit resources through the UI
See the Postman Collection for a pre-built collection of API requests.