ra-data-postgrest
ra-data-postgrest copied to clipboard
Allow passing extra headers via meta
Postgrest supports calling functions with a single JSON parameter by sending the header Prefer: params=single-object
with your request.
This PR allows you to add any kind of header to your request using RA4's meta
parameter. I chose this solution instead of something like a meta.singleJsonParameter boolean, because allowing to add any header makes the react-admin app more flexible, because many other Postgrest features are also activated by sending an additional header.
Example usage:
const [create, { isLoading, error }] = useCreate(
'rpc/my-function',
{
data: { ... },
meta: { headers: { Prefer: 'params=single-object' } },
}
);
I'm open for discussions or making adjustments to this PR...
Btw I noticed code formatting is not enforced by something like prettier in this repo, so I tried to format my changes the best that I could to adhere to the current formatting.