Giter VIP home page Giter VIP logo

api_builder's Introduction

Api Config Builder

Package Info:

This is an utility of api config builder base on axios package. It make more easily to create new a http request and handling response.

Installing Package:

npm install api-config-builder

Table methods:

Method name Descriptions Note
addConfig Adding any config for a http request Read axios config
addParam Adding single query param or path param specify key and value string Content
addParams Adding object quey param or path param Include 1 or more properties
addHeader Adding single header with key-value pair string Content
addHeaders Adding object header with more properties Content
sendRequest Create a http request and send it with all config added Content

Usage:

  1. import module Api Config Builder
import ApiRequestBuilder from 'api-config-builder';
  1. Create object Api Config Builder:
const builder = new ApiRequestBuilder();
  1. Create a http request
const response = builder
            .addConfig('baseURL', 'http://localhost:9001')
            .addConfig('method', 'get')
            .addConfig('url', '/:version/customers/customer-core/{cgid}')
            .addHeader('x-channel', 'mobile')
            .addHeader('token', '123-abc')
            .addHeaders({ 'x-metadata': '123123123', 'x-version': 1.9 })
            .addParam(PARAM_TYPE.PATH, 'version', 'v1')
            .addParam(PARAM_TYPE.PATH, 'cgid', '200101HYPHEN020235000CM3')
            .addParam(PARAM_TYPE.QUERY, 'partyType', 'ORG')
            .addParam(PARAM_TYPE.QUERY, 'cgid', '123123123')
            .addParam(PARAM_TYPE.QUERY, 'transRef', 'LMBULK321')
            .sendRequest();

Note: You can declare a placeholder for path param in url endpoint like this

addConfig('url', '/:version/customers/customer-core/:cgid')

or

addConfig('url', '/{version}/customers/customer-core/{cgid}')

then assign value addParam method:

.addParam(PARAM_TYPE.PATH, 'version', 'v1')
            .addParam(PARAM_TYPE.PATH, 'cgid', '200101HYPHEN020235000CM3')

Publish package:

- npm run build
- npm publish

api_builder's People

Contributors

huymapmap40 avatar

Stargazers

 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.