Function sendPost

  • Sends a POST request to a specified URL with a given body and Bearer Token. Content-Type is set to application/json.

    Type Parameters

    • T

      The type of the request body.

    Parameters

    • url: string

      The URL to send the POST request to.

    • body: T

      The body of the POST request.

    • Optional token: string

      Optional token to be included in the Authorization header.

      Optional

    Returns Promise<Response>

    The response from the POST request.

    Example

    const response = await sendPost<{ name: string }>('https://api.example.com/users', { name: 'Alice' }, 'mytoken123');
    const data = await response.json();
    console.log(data);

    Throws

    Will throw an error if the POST request fails, including the failed request body.

Generated using TypeDoc