4. Response Envelope (The Outer Wrapper)#
Every JsonDispatch response is wrapped in a predictable, minimal envelope. This gives every API the same shape — regardless of what the data is — making client logic simpler and responses easier to debug.
The envelope helps you quickly understand:
what happened (
status,message)what’s returned (
data)how to interpret it (
_properties)how to resolve references (
_references)how to navigate further (
_links)
4.1 Top-Level Members at a Glance#
A JsonDispatch response body may contain these top-level members:
Key |
Type |
Required |
Purpose |
|---|---|---|---|
|
string |
✅ |
Overall result — |
|
string |
⚪ |
Short, human-readable explanation. |
|
mixed |
⚪ |
Main payload (object, array, or scalar). |
|
object |
⚪ |
ID-to-label mapping dictionary. |
|
object |
⚪ |
Metadata describing structure, count, or schema. |
|
object |
⚪ |
Navigation links (pagination, related resources). |
Note
⚪ = optional, depending on the status value and context.
4.2 status — Success, Fail or Error#
The status field defines the overall outcome of the request.
``success`` → the request completed successfully and data is returned.
``fail`` → the client provided invalid input (validation, missing fields, etc.).
``error`` → the server or an external dependency failed to process the request.
Example
{
"status": "success",
"data": {
"id": 42,
"title": "JsonDispatch in Action"
}
}
4.3 message — Keep It Human-Friendly#
message is a short sentence for humans (not parsers). Use it as a quick, meaningful summary in logs or UI alerts.
Context |
Example message |
|---|---|
success |
|
fail |
|
error |
|
4.4 data — Your Actual Payload#
Everything your API returns lives under data.
The format should remain consistent for the same (version, method, endpoint) combination.
Status |
Expected |
Description |
|---|---|---|
success |
object / array / any |
The requested resource(s). |
fail |
array |
List of validation issues. |
error |
array |
List of system or dependency errors. |
Example — Success Payload
"data": {
"type": "article",
"attributes": {
"id": 42,
"title": "JsonDispatch in Action",
"category": 1
}
}
4.5 _references — Turning IDs Into Meaning#
Instead of making clients hard-code enums or category lookups, _references provides an instant dictionary for ID
resolution.
Example
{
"_references": {
"category": {
"1": "News",
"2": "Tutorial",
"3": "Opinion"
}
}
}
Now clients can map "category": 2 → “Tutorial” without additional API calls.
4.6 _properties — Describing Data Context#
_properties gives structure-level metadata that describes your payload — useful for UI builders, pagination, or
deprecation notices.
Common keys include:
Key |
Type |
Purpose |
|---|---|---|
|
string |
Resource type ( |
|
string |
Logical name of the resource. |
|
int |
Total item count (if paginated). |
|
int |
Current page number (if applicable). |
|
string |
Item range in current response (e.g., |
|
url |
Optional schema or structure reference. |
|
url |
Optional migration or deprecation notice. |
Example
"_properties": {
"data": {
"type": "array",
"name": "articles",
"count": 20,
"page": 2,
"range": "21–40",
"deprecation": "https://api.example.com/docs/v2/articles"
}
}
4.7 _links — Pagination and Beyond#
_links makes your API navigable. It can include pagination links, related resources, or documentation references.
Example — Pagination
{
"_links": {
"self": "https://api.example.com/articles?page=2",
"next": "https://api.example.com/articles?page=3",
"prev": "https://api.example.com/articles?page=1"
}
}
Example — Related Resources
{
"_links": {
"self": "https://api.example.com/articles/42",
"author": "https://api.example.com/users/99",
"comments": "https://api.example.com/articles/42/comments"
}
}
4.8 Envelope Summary#
Section |
Purpose |
Optional |
|---|---|---|
|
Defines success/fail/error outcome |
❌ No |
|
Human-readable summary |
⚪ Yes |
|
Payload or error details |
⚪ Yes |
|
Lookup tables for enums or IDs |
⚪ Yes |
|
Metadata about the response |
⚪ Yes |
|
Pagination or relational navigation |
⚪ Yes |
👉 Together, these create a consistent, machine-parsable yet human-friendly response pattern across all JsonDispatch APIs.