Visit https://xivapi.com/docs for documentation about the web api mapped by this client.
Further documentation for this library available on documentation website: https://xivapi.github.io/angular-client/
Simply run npm i --save @xivapi/angular-client
Add XivapiClientModule to your AppModule imports:
@NgModule({declarations: [AppComponent,],imports: [
...
XivapiClientModule.forRoot(), ...
],bootstrap: [AppComponent]})exportclassAppModule{}In the other modules, don't call forRoot again, just import the module itself.
Then you can simply inject the service wherever you want to use it:
@Component({
...
})exportclassFooComponent{publicitems$: Observable<XivapiList<any>>;constructor(privatexivapi: XivapiService){this.items$=this.xivapi.getList(XivapiEndpoint.Items);}}- Create a google cloud function, name it as you want.
- Insert following code (with your key):
exports.xivapiProxy=(req,res)=>{letrequest=require('request');constapiKey='<your api key>>';res.set('Access-Control-Allow-Origin','<your allowed origins>').set('Access-Control-Allow-Headers','Content-Type');consturl=Buffer.from(req.query.url,'base64').toString();request({url:`${url}${url.indexOf('?')>-1 ? '&':'?'}private_key=${apiKey}`,},function(error,response,body){leterrorBody=JSON.parse(body);leterrorMessage=errorBody.error||errorBody.message;if(error||errorMessage){res.status(400).send(errorMessage||'Unknown Error');}else{res.status(200).set('Content-Type','application/json').send(body);}});};- Enable proxy mode inside the api module:
XivapiClientModule.forRoot('<GCF trigger url>')Example url: https://us-central1-myproject.cloudfunctions.net/xivapi-proxy
Keep in mind that you can enable it based on the current environment, simply give null as proxy url if environment isn't prod,
to use "normal" mode in order to get better debugging
when using dev environment.