Example

Partial Responses

Demonstrates how to enable Helix partial JSON responses. Shows the fields query parameter trimming a raw JSON document down to just the requested properties.
Group
REST API
Path
examples/rest-api/partial-responses

Overview

Helix Spring Boot webservice that shows how to enable partial JSON responses and let clients ask for a subset of

fields through the query string.

Run this example from the shared examples build:

Run

Run this example from the shared examples build


./gradlew -p examples runExample -Pexample=rest-api/partial-responses --init-script "$(pwd)/helix.init.gradle"

What It Shows

  • the Helix API starter baseline
  • enabling partial response processing with helix.partialresponse.enabled=true
  • the default partial response query parameter name, fields
  • returning a raw DTO so field filtering is easy to observe directly
  • using an application/*+json media type so the Helix partial-response message converter handles the response

Endpoints

  • GET /v1/partial-responses/customers/current
  • GET /liveness
  • GET /health

Example full response

{
  "customerId": "cust-1001",
  "name": "Ada Lovelace",
  "tier": "gold",
  "email": "ada@example.com"
}

Example partial response

{
  "customerId": "cust-1001",
  "tier": "gold"
}

Development

Building the Application

Run the following command to build the service:

Command

Building the Application


./gradlew clean build

Testing the Application

Run the following command to run the service tests:

Command

Testing the Application


./gradlew test
./gradlew integration

Trying the API

Run the service:

Then try:

The first request returns the full customer document. The second request enables the Helix partial-response converter by including the fields query parameter, and the response is trimmed to just the selected properties.

Command

Trying the API


./gradlew bootRun

Command

Trying the API


curl -H 'Accept: application/vnd.helix+json' \
  http://localhost:8080/v1/partial-responses/customers/current

curl -H 'Accept: application/vnd.helix+json' \
  'http://localhost:8080/v1/partial-responses/customers/current?fields=customerId,tier'