Gabb-c / pokenode-ts

A lightweight Node.js wrapper for the PokéAPI with built-in types.
https://pokenode-ts.vercel.app/
MIT License
244 stars 28 forks source link

Why is `baseURL` unset in `getResourceByUrl`? #903

Closed Gabb-c closed 9 months ago

Gabb-c commented 1 year ago

Discussed in https://github.com/Gabb-c/pokenode-ts/discussions/887

Originally posted by **nitwhiz** August 13, 2023 `getResourceByUrl` requests without the base-url set in the client used for this request. Why is it designed this way? https://github.com/Gabb-c/pokenode-ts/blob/6572881e692bd6e305e8c8f37851fb892a171a68/src/clients/utility.client.ts#L50-L54 This makes it hard to use this client with a selfhosted instance of the PokeAPI JSON-files, where following the urls in the responses is necessary.
Gabb-c commented 1 year ago

Now the Base URL can be changed if needed:

protected async getResourceByURL<T>(url: string, baseURL = BASE_URL.REST): Promise<T> {
    const ENDPOINT = url.split("v2")[1] as string;
    return (await this.api.get<T>(ENDPOINT, { baseURL })).data;
}

Example:

import {  UtilityClient } from "pokenode-ts";

const client = new UtilityClient();

const data = client.getResourceByUrl("https://pokeapi.co/api/v2/pokemon/luxray", "customPokeAPIInstance");
stale[bot] commented 10 months ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] commented 9 months ago

This issue has been automatically closed because it has not had recent activity. Thank you for your contributions.