Have the ability to specify the base URL as a client option
simonorono opened this issue · 2 comments
simonorono commented
Describe the feature you'd like to request
I'd like to be able to use my local instance of the PokeAPI with this library.
For the app I'm creating, I use the PokeAPI to generate data files during development time. To avoid making lots of calls to the PokeAPI, I host a local instance of it. I would like to use this library with my local instance of the PokeAPI.
Describe the solution you'd like
I believe that adding the base URL as an optional parameter to the ClientArgs
interface would be the best solution and, if empty, use BaseURL.REST
.
Describe alternatives you've considered
I created a wrapper class around MainClient
that replaced the api
instance of each client with my own:
import { ClientArgs, MainClient } from "pokenode-ts"
import { setup } from 'axios-cache-adapter';
export class CustomClient extends MainClient {
constructor(clientArgs?: ClientArgs) {
super(clientArgs);
[
this,
this.berry,
this.contest,
this.encounter,
this.evolution,
this.game,
this.item,
this.location,
this.machine,
this.move,
this.pokemon,
].forEach(_ => _.api = setup({
baseURL: 'http://localhost/api/v2',
headers: {
'Content-Type': 'application/json',
},
cache: {
maxAge: clientArgs?.cacheOptions?.maxAge || 0,
...clientArgs?.cacheOptions,
},
})
)
}
}
If the proposal is accepted, I could code the feature.
Gabb-c commented
Hey @simonorono. LGTM, feel free to contribute to pokenode-ts with this feature.