Git Product home page Git Product logo

angular-client's Introduction

angular-client

CircleCI npm version

Documentation

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/

Installation

Simply run npm i --save @xivapi/angular-client

Quick start

Add XivapiClientModule to your AppModule imports:

@NgModule({
    declarations: [
        AppComponent,
    ],
    imports: [
        ...
        XivapiClientModule.forRoot(),        
        ...
    ],
    bootstrap: [AppComponent]
})
export class AppModule {
}

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({
    ...
})
export class FooComponent {
    
    public items$: Observable<XivapiList<any>>;
    
    constructor(private xivapi: XivapiService){
        this.items$ = this.xivapi.getList(XivapiEndpoint.Items);
    }
}

Use with private_key (Google Cloud Function)

  • Create a google cloud function, name it as you want.
  • Insert following code (with your key):
exports.xivapiProxy = (req, res) => {
  let request = require('request');
  const apiKey = '<your api key>>';
  res.set('Access-Control-Allow-Origin', '<your allowed origins>')
     .set('Access-Control-Allow-Headers', 'Content-Type');
  const url = Buffer.from(req.query.url, 'base64').toString();
  request(
    {
      url:`${url}${url.indexOf('?') > -1 ? '&':'?'}private_key=${apiKey}`,
    }, 
    function(error, response, body) {
    let errorBody = JSON.parse(body);
	let errorMessage = 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.

angular-client's People

Contributors

ayyaruq avatar hatt avatar latenightwreck avatar supamiu avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.