Skip to content
The Path

Module 6 · FHIR·12 min

The FHIR REST API

Read, create, search: the basic requests and the Bundle.

In v2, the sleep lab pushes Marie Dubois’s AHI to the hospital record as soon as the result is validated:

The result leaves on its own for the hospital record, at the lab’s initiative.

ORU^R01· Observation result (unsolicited)
||||||||||
||||||||
||||||||||||||

In FHIR, the patient app can ask for that result when Marie opens her phone. To do so, it talks to the FHIR server with four web verbs (GET, POST, PUT, DELETE) and a handful of rules.

The base address

Every FHIR server has a base address, written [base] in the standard. For example https://fhir.clinique-leleux.example. Each resource lives under that base, at [base]/[type]/[id].

Read: GET

GET [base]/Patient/1024
Accept: application/fhir+json

The server answers 200 OK with the resource. If the patient does not exist: 404 Not Found. If she existed but was deleted: 410 Gone. The nuance matters: 410 says “she was here”; 404 says “I cannot find her”, which can also mean the server kept no record of the deletion.

Create: POST

POST [base]/Observation
Content-Type: application/fhir+json

(the Observation resource as JSON, without an id)

You send the resource without an id: the server assigns it. If it accepts, it answers 201 Created with a Location header giving the new address, for example [base]/Observation/iah-0042/_history/1. The _history/1 part is the version number.

Update: PUT

PUT [base]/Observation/iah-0042

The body holds the complete resource, with the same id as in the URL. PUT replaces, it does not patch. Response: 200 OK if the resource existed, 201 Created if the server allows creation through PUT and it did not exist.

To change only part of a resource, FHIR also defines PATCH. Not every server accepts it.

Delete: DELETE

DELETE [base]/Observation/iah-0042

The server answers 200 OK or 204 No Content (success, nothing to send back). Reading the same address then returns 410 Gone if the server keeps track of deletions, or 404 Not Found if it does not.

Search: GET with parameters

Search is what makes FHIR so handy. You send a GET on the resource type, with parameters:

GET [base]/Observation?patient=1024&code=http://loinc.org|69990-0&date=ge2026-01-01

Read it left to right:

  • patient=1024: Observations whose subject is patient 1024;
  • code=http://loinc.org|69990-0: that carry LOINC code 69990-0, which the clinic sends as the alternate code for its AHI (the terminologies lesson explains why it is not a perfect fit). The vertical bar separates the system from the code. In a real client, it is often encoded as %7C;
  • date=ge2026-01-01: measured on or after 1 January 2026. ge means “greater than or equal”, le “less than or equal”.

Each resource has its own list of search parameters, given on its page in the standard. For Observation: patient, code, date, category, and more.

The answer: a Bundle

A successful search returns 200 OK and a Bundle of type searchset: a package that holds the results.

{
  "resourceType": "Bundle",
  "type": "searchset",
  "total": 1,
  "link": [
    {
      "relation": "self",
      "url": "https://fhir.clinique-leleux.example/Observation?patient=1024&code=http://loinc.org|69990-0"
    }
  ],
  "entry": [
    {
      "fullUrl": "https://fhir.clinique-leleux.example/Observation/iah-0042",
      "resource": {
        "resourceType": "Observation",
        "id": "iah-0042",
        "status": "final",
        "code": {
          "coding": [
            { "system": "https://fhir.clinique-leleux.example/CodeSystem/labo-sommeil", "code": "AHI" },
            { "system": "http://loinc.org", "code": "69990-0" }
          ]
        },
        "subject": { "reference": "Patient/1024" },
        "valueQuantity": {
          "value": 28.5,
          "unit": "/h",
          "system": "http://unitsofmeasure.org",
          "code": "/h"
        }
      },
      "search": { "mode": "match" }
    }
  ]
}

total gives the number of hits. Each entry carries the full address of the resource (fullUrl), the resource itself, and search.mode: match for a hit. No hits? Still 200, with an empty Bundle.

The transaction Bundle: all or nothing

A Bundle can also send several resources at once. With type transaction, each entry carries a request (method and URL), and the server applies all or nothing: if a single write fails, none is saved. Handy for creating the polysomnography report and its Observations together.

There are other Bundle types: batch (each entry processed on its own), document, message, history, collection.

The CapabilityStatement: the server’s ID card

GET [base]/metadata

The server answers with its CapabilityStatement: its FHIR version, the resources it handles, the allowed interactions and the search parameters it understands. It is the first request to send to an unfamiliar server. The closest v2 equivalent is the interface specification, except this one is machine-readable.

HTTP status codes to know

Code When
200 OK Successful read, search or update
201 Created Resource created
204 No Content Success, no response body (often after a DELETE)
400 Bad Request Resource unreadable or invalid
404 Not Found Unknown resource
410 Gone Deleted resource
422 Unprocessable Entity The resource breaks a profile or a server business rule

On errors, the server normally attaches an OperationOutcome resource explaining the problem. It plays the role of the ERR segment in a v2 acknowledgement.

Practise on a public server

No need to install a server to try this. The HAPI FHIR project runs a public test server at hapi.fhir.org, open without authentication. You can send GETs and searches from any REST client, or even your browser.

Check your understanding

1 of 4

You send POST [base]/Observation with a new Observation. The server accepts it. Which HTTP status do you get?

+50 XPPass the quiz (3 correct answers) to complete the lesson.

Reviewed and checked on 27 September 2026