@nhost/nhost-js
Version:
Nhost JavaScript SDK
57 lines • 2.54 kB
TypeScript
/**
* Functions client for the Nhost JavaScript SDK.
*
* This module provides functionality for executing serverless function calls
* against Nhost serverless functions.
*/
import { type ChainFunction, type FetchResponse } from '../fetch';
/**
* Functions client interface providing methods for executing serverless function calls
*/
export interface Client {
baseURL: string;
/** Add a middleware function to the fetch chain
* @param chainFunction - The middleware function to add
*/
pushChainFunction(chainFunction: ChainFunction): void;
/**
* Execute a request to a serverless function
* The response body will be automatically parsed based on the content type into the following types:
* - Object if the response is application/json
* - string text string if the response is text/*
* - Blob if the response is any other type
*
* @param path - The path to the serverless function
* @param options - Additional fetch options to apply to the request
* @returns Promise with the function response and metadata.
*/
fetch<T = unknown>(path: string, options?: RequestInit): Promise<FetchResponse<T>>;
/**
* Executes a POST request to a serverless function with a JSON body
*
* This is a convenience method assuming the request is a POST with JSON body
* setting the `Content-Type` and 'Accept' headers to `application/json` and
* automatically stringifying the body.
*
* For a more generic request, use the `fetch` method instead.
*
* @param path - The path to the serverless function
* @param body - The JSON body to send in the request
* @param options - Additional fetch options to apply to the request
* @returns Promise with the function response and metadata
*/
post<T = unknown>(path: string, body?: unknown, options?: RequestInit): Promise<FetchResponse<T>>;
}
/**
* Creates a Functions API client for interacting with serverless functions.
*
* This client provides methods for executing requests against serverless functions,
* with support for middleware functions to handle authentication, error handling,
* and other cross-cutting concerns.
*
* @param baseURL - Base URL for the functions endpoint
* @param chainFunctions - Array of middleware functions for the fetch chain
* @returns Functions client with fetch method
*/
export declare const createAPIClient: (baseURL: string, chainFunctions?: ChainFunction[]) => Client;
//# sourceMappingURL=client.d.ts.map