Skip to content

Standard Responses

ResourcesJS exports one optional response helper: response.ok().

import { response } from "@amrachraf6690/resourcesjs";
return response.ok(UserResource.make(user));

Output:

{
"success": true,
"data": {
"id": 1
}
}

Resource metadata is preserved:

{
"success": true,
"data": {
"id": 1
},
"meta": {
"version": "1.0"
}
}

Only branded Resource envelopes are flattened. Ordinary values are wrapped under data, even if they already contain a data property.

response.ok({ data: "ordinary" });
{
"success": true,
"data": {
"data": "ordinary"
}
}