Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

api-cg-lib

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

api-cg-lib

Library that gets data from an Api.

  • 1.1.7
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

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/"
                }
            }
        ]
    }
}

Keywords

FAQs

Package last updated on 29 May 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc