--- title: "Send Hooks" slug: "send-hooks" updated: 2026-05-05T19:28:27Z published: 2026-05-05T19:28:27Z canonical: "docs.xgen.ai/send-hooks" --- > ## Documentation Index > Fetch the complete documentation index at: https://docs.xgen.ai/llms.txt > Use this file to discover all available pages before exploring further. # Send Hooks Sometimes you may want to modify the request data globally or to customize the response. To accomplish this, the SDK provides 2 function hooks: 1. `beforeSend` 2. `afterSend` --- ## beforeSend - `beforeSend` - triggered right before sending the fetch request, allowing you to inspect/modify the request config. ```javascript const xg = new XGenClient({/* params */}); xg.beforeSend = function ({url, options}) {    // For list of the possible request options properties check    // https://developer.mozilla.org/en-US/docs/Web/API/fetch#options    options.headers = Object.assign({}, options.headers, {        'X-Custom-Header': 'example',    });    return { url, options }; }; ``` --- ## afterSend `afterSend` - triggered after successfully sending the fetch request, allowing you to inspect/modify the response object and its parsed data. ```javascript const xg = new XGenClient({/* params */}); xg.afterSend = function ({response, data}) {    // do something with the response state    console.log(response.status);    return Object.assign(data, {        // extend the data...        "newField": "This is added to the data of the response",    }); }; ``` ##