Invoke Functions
Call deployed Carpo Functions with a Fetch compatible request.
The browser client and both server clients expose functions. The deployed Function's invocation mode, CORS policy, limits, and access rules decide whether the request is accepted.
const response = await carpo.functions.invoke('function-id', {
path: '/users/me?include=teams',
method: 'GET',
})
const currentUser = await response.json()invoke() returns the native Fetch Response, including for non JSON bodies and streaming responses. It does not throw for a non 2xx response. Check response.ok or handle the response status yourself.
For a JSON response, use invokeJson<T>(). It parses the body and throws CarpoApiError when the response is not successful:
const created = await carpo.functions.invokeJson<{ id: string }>('function-id', {
path: '/todos',
method: 'POST',
json: { title: 'Ship the change' },
})Request options
pathis a local path starting with/. It can include a query string, but cannot change the Function origin. The default is/.methoddefaults toGET.- Pass
jsonfor a JSON body orbodyfor a stream, form, binary, or text body. They cannot be used together. GETandHEADcalls cannot include a body.headers,signal, andcredentialsfollow Fetch request behavior.environmentcan override the client's configured environment for one invocation.
Project Auth credentials are forwarded by default. A bearer token can be supplied by the client's getAccessToken getter. Do not include a server key in a browser app.