webhookHooks

What is that, and how use it?

Hooks are optional functions that can be passed per-request to run custom logic at key moments in the request lifecycle.


Basic Example

const hooks: ShapeRQHooks = {
  onRequest: () => {
    console.log("Starting request...");
  },
  onResponse: (data) => {
    console.log("Response data:", data);
  },
  onError: ({error}) => {
    console.error("Error in request!", error);
  },
};

await httpGet("Main", "user/me", { hooks });

onRequest

Runs before the request is sent.


onResponse

Called after a successful request with no server-side errors.


onError

Called when the request fails, including network issues or server errors.

Also you can use onError for retries


Hook Summary

Hook
Trigger
Async Allowed

onRequest

Before request

โŒ

onResponse

After successful response (2xx)

โŒ

onError

On any failure or thrown error

โœ…

Last updated