Skip to content

Requests

dysolix edited this page Jan 8, 2025 · 4 revisions

request Function Overview

The request function leverages Hasagi's auto-generated LCU types, providing:

  • Auto-complete suggestions in editors like VS Code.
  • Automatic request parameter types and response types.

This enhances productivity and ensures type safety while working with APIs.

Overloads

The request function supports two overloads, allowing flexibility depending on your requirements.

1. Overload with Method, Path, and Options

This overload uses auto-generated types for the parameters and responses. It takes up to three parameters:

  1. Method: The HTTP method (e.g., get, put, post).
  2. Path: The endpoint URL.
  3. Options (optional or required depending on endpoint): Additional request configurations such as the body, path parameters, query parameters and headers

Examples

// Simplified usage: Method and path only
await client.request("get", "/lol-summoner/v1/current-summoner");

// Including options: The options parameter is required because the endpoint's request body is required
await client.request("put", "/lol-perks/v1/currentpage", { body: 123 });

2. Overload with AxiosConfig

This overload accepts a single parameter of type AxiosConfig and does not infer any LCU types. It includes an optional property, returnAxiosResponse, which determines the behavior of the response:

  • Without returnAxiosResponse: Directly returns the data property of the AxiosResponse object.
  • With returnAxiosResponse: true: Returns the full AxiosResponse object.

Examples

// Default behavior: Returns the data property of the AxiosResponse object
await client.request({
    method: "get",
    url: "/lol-summoner/v1/current-summoner"
});

// With returnAxiosResponse set to true: Returns the full AxiosResponse object
await client.request({
    method: "get",
    url: "/lol-summoner/v1/current-summoner",
    returnAxiosResponse: true
});