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

api-cg-lib

v1.1.7

Published

Library that gets data from an Api.

Downloads

48

Readme

N|Solid

api-cg-lib

https://github.com/CloudGenUser/api-cg-lib.git

1. Introduction

This code has the objective to get information of an API, no matter if the API is public or requires access permission.

This library could be used as part of a component based on Open Integration Hub (OIH) framework or any Nodejs development that requires API calls on it.

2. Library usage

The library can be installed from npm page with the next:

npm install api-cg-lib, npm i api-cg-lib or yarn install api-cg-lib

2.1. Api without security

  • Arguments:

    • Required:

      • method: This specifies if the method of the request is one of the next: GET, POST, PUT, DELETE, or BATCH.
      • api: In this attribute must be specified the path or URL to connect with the API.
    • Optionals:

      • addData: It can be specified an additional parameter or content that could be required by the API as part of the request. The API owner must provide the required information to use the API and obtain the expected result.
      • auth: If required by the API this parameter allows to define if it requires a token or credentials to be used to connect to the API. If this parameter is submitted, the parameter "authType" is mandatory.
      • authType: This parameter specifies the type of authentication like bearer, basic, oath or other according with the authentication method of the API. If this parameter is set the "auth" parameter is required.
  • Description: This code creates a request to get information from an API according with the parameter in the call. The correspondig configurations are provided by the API owner and should be set in the corresponding parameters of this library. Once the request is received and processed by the API the respose is sent back with the result. The result is a JSON structure in a string format with the content of the result by the API, it could be the expected result or an error message if the API couldn't process the request.

  • Sample request:

{"api": "https://pokeapi.co/api/v2/pokemon/ditto", "method": "get"}

Response of the sample request (fragment):

{
    "content": {
        "abilities": [
            {
                "ability": {
                    "name": "limber",
                    "url": "https://pokeapi.co/api/v2/ability/7/"
                }
            }
        ]
    }
}

2.2 Api with security

  • Arguments:
    • Required:

      • method: This specifies if the method of the request is one of the next: GET, POST, PUT, DELETE, or BATCH.
      • api: In this attribute must be specified the path or url to connect with the API.
      • auth: In this cases when an authentication is required by the API this parameter allows to define the token or credentials to be used to connect to the API. If this parameter is submited, the parameter "authType" is mandatory.
      • authType: This parameter specifies the type of authentication like bearer, basic, oauth or other according with the authentication method of the API. This parameter requires to be configured along with the "auth" parameter.
    • Optionals:

      • addData: It can be specified an additional parameter or content that could be required by the API as part of the request. The API owner must provide the required information to use the API and obtain the expected result.
  • Description: This code create a request to get information from an API according with the parameter in the call. Once the request is received and processed by the API the respose is sent back with the result. The result will be in a string format with a JSON structure with the content of the result by the API, it could be the expected result or an error message if the API couldn't process the request.
  • Sample of a request:
{"method": "POST","api": "https://elastic.test.com/tempo/","auth": "ZWxhc3RpYzpFGHdGlj","authType":"Basic","addData":{"valorprueba":"prueba"}}

Resultant sample (fragment):

{
    "content": {
        "abilities": [
            {
                "ability": {
                    "name": "limber",
                    "url": "https://pokeapi.co/api/v2/ability/7/"
                }
            }
        ]
    }
}