Giter VIP home page Giter VIP logo

node-zdf-api-client's Introduction

Introduction

The library is useful for incorporating API Token Lifecycle Management into a project by preventing the use of a pre-generated token.

Install

npm install --save "git+https://github.com/werty1st/node-zdf-api-client.git#2.0.1"

The module will be installed and added to the package.json.

Usage Example

  • First copy the .npmrc_default of this Repository to .npmrc in your Project's root directory or ensure otherwise to set the API environment variables. ❗Don't forget to add .npmrc to .gitignore.❗

  • Load the Module and initialize it.

const ZDFApi = require('node-zdf-api-client');

const API_CLIENT = process.env.apiclient;
const API_SECRET = process.env.apisecret;
const API_HOST   = process.env.apihost;

const zdfapi = new ZDFApi(API_CLIENT, API_SECRET, API_HOST);
  • Add the authentication token to the request.
async function downloadUrl(url){
    
    const token = await zdfapi.token;
    
    return request({
        url: url,
        method: 'GET',
        headers: {
            'Api-Auth': `bearer ${token.access_token}`,
            'Accept': "application/vnd.de.zdf.v1.0+json;charset=utf-8"
        },
        resolveWithFullResponse: true
    });

}
  • For batch Tasks the Token is writte to the filesystem. This prevents the API Client to request a new token each time. You may want to exclude this file (API_HOST.token.json) from git too.

Optional

  • For long running Tasks the API Client schedules a Token refresh Task. This can be turned off by calling:
zdfapi.once("token-ready",zdfapi.stopTokenRefreshTask);

Test

npm test

Run test output

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.