-
Notifications
You must be signed in to change notification settings - Fork 1
Requests
dysolix edited this page Jan 8, 2025
·
4 revisions
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.
The request
function supports two overloads, allowing flexibility depending on your requirements.
This overload uses auto-generated types for the parameters and responses. It takes up to three parameters:
-
Method: The HTTP method (e.g.,
get
,put
,post
). - Path: The endpoint URL.
- Options (optional or required depending on endpoint): Additional request configurations such as the body, path parameters, query parameters and headers
// 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 });
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 thedata
property of theAxiosResponse
object. -
With
returnAxiosResponse: true
: Returns the fullAxiosResponse
object.
// 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
});