npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

apiclient

v0.2.5

Published

request wrapper

Downloads

201

Readme

API client

Build Status

API client adalah request wrapper

Basically, ApiClient is just a request wrapper. It wrap all request to more structured way. The way we separate remote endpoint specification from coding overhead.

Because of apiclient is just wrapping request, any of request options can be used here.

Usage

To access these URLs, we use apiclient this way :

URLs:

  • GET https://remote.apihost.com:443/v1/api/user/1?apikey=asdf2345kjhnkj
  • POST https://remote.apihost.com:443/v1/api/user?apikey=asdf2345kjhnkj
  • PUT https://remote.apihost.com:443/v1/api/user/1?apikey=asdf2345kjhnkj
  • DELETE https://remote.apihost.com:443/v1/api/user/1?apikey=asdf2345kjhnkj
var Apiclient = require('apiclient');
var seed = {
  base: {
    protocol: 'https',
    hostname: 'remote.apihost.com',
    port: 443,
    pathname: 'v1/api'
  },
  path: {
    GET: {
      user: {
        location: 'user/%(userid)d',
        query: {
          apikey: 'asdf2345kjhnkj'
        }
      }
    },
    POST: {
      user: {
        location: 'user',
        query: {
          apikey: 'asdf2345kjhnkj'
        }
      }
    },
    PUT: {
      user: {
        location: 'user/%(userid)d',
        query: {
          apikey: 'asdf2345kjhnkj'
        }
      }
    },
    DELETE: {
      user: {
        location: 'user/%(userid)d',
        query: {
          apikey: 'asdf2345kjhnkj'
        }
      }
    }
  }
}

var Api = new Apiclient(seed);

Api.get('user', {userid: 1}, {}, function (error, response, body) {
  console.log(error, response, body);
});

Api.post('user', {}, {
  body: {
    username: 'John',
    password: 'John123'
  }
}, function (error, response, body) {
  console.log(error, response, body);
});

Api.put('user', {userid: 1}, {}, function (error, response, body) {
  console.log(error, response, body);
});

Api.delete('user', {userid: 1}, {}, function (error, response, body) {
  console.log(error, response, body);
});

Functions

ApiClient(data)

ApiClient constructor

Kind: global function

| Param | Type | Description | | --- | --- | --- | | data | Object | Seed data. |

apiClient.download(api, param, options, callback) ⇒ Void

Download file from server

Kind: instance method of ApiClient
Returns: Void - Nothing to return.

| Param | Type | Description | | --- | --- | --- | | api | String | Endpoint API. | | param | Object | Parameter url object. | | options | Object | Request option object. | | callback | function | Callback function. |

apiClient.get(api, param, options, callback) ⇒ Void

Get thing from server using method HTTP GET

Kind: instance method of ApiClient
Returns: Void - Nothing to return.

| Param | Type | Description | | --- | --- | --- | | api | String | Endpoint API. | | param | Object | Parameter url object. | | options | Object | Request option object. | | callback | function | Callback function. |

apiClient.postUpload(api, param, options, callback) ⇒ Void

Upload file to server using POST method with attached file on body.

Kind: instance method of ApiClient
Returns: Void - Nothing to return.

| Param | Type | Description | | --- | --- | --- | | api | String | Endpoint API. | | param | Object | Parameter url object. | | options | Object | Request option object. | | callback | function | Callback function. |

apiClient.postForm(api, param, options, callback) ⇒ Void

Upload file to server using POST method with attached file on body, formatted as multipart form.

Kind: instance method of ApiClient
Returns: Void - Nothing to return.

| Param | Type | Description | | --- | --- | --- | | api | String | Endpoint API. | | param | Object | Parameter url object. | | options | Object | Request option object. | | callback | function | Callback function. |

apiClient.post(api, param, options, callback) ⇒ Void

Send string via POST method. This API will keep body on memory, attaching big string more than 1MB is not recommended, as it will fill the memory so fast.

Kind: instance method of ApiClient
Returns: Void - Nothing to return.

| Param | Type | Description | | --- | --- | --- | | api | String | Endpoint API. | | param | Object | Parameter url object. | | options | Object | Request option object. | | callback | function | Callback function. |

apiClient.putForm(api, param, options, callback) ⇒ Void

Send data using PUT method with multipart/form-data format body.

Kind: instance method of ApiClient
Returns: Void - Nothing to return.

| Param | Type | Description | | --- | --- | --- | | api | String | Endpoint API. | | param | Object | Parameter url object. | | options | Object | Request option object. | | callback | function | Callback function. |

apiClient.put(api, param, options, callback) ⇒ Void

Send data using PUT method with raw string body.

Kind: instance method of ApiClient
Returns: Void - Nothing to return.

| Param | Type | Description | | --- | --- | --- | | api | String | Endpoint API. | | param | Object | Parameter url object. | | options | Object | Request option object. | | callback | function | Callback function. |

apiClient.delete(api, param, options, callback) ⇒ Void

Send data using DELETE method with raw string body.

Kind: instance method of ApiClient
Returns: Void - Nothing to return.

| Param | Type | Description | | --- | --- | --- | | api | String | Endpoint API. | | param | Object | Parameter url object. | | options | Object | Request option object. | | callback | function | Callback function. |

isEmptyObject(obj) ⇒ Boolean

Check if is object empty

Kind: global function
Returns: Boolean - Return true if empty or false otherwise.

| Param | Type | Description | | --- | --- | --- | | obj | Object | Object to be Check |