1.1.7 • Published 7 months ago

api-cg-lib v1.1.7

Weekly downloads
-
License
ISC
Repository
-
Last release
7 months ago

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

7 months ago

1.1.6

9 months ago

1.1.5

9 months ago

1.1.4

11 months ago

1.1.3

11 months ago

1.1.2

11 months ago

1.1.1

1 year ago

1.1.0

1 year ago

1.0.9

1 year ago

1.0.8

1 year ago

1.0.10

1 year ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago

0.0.2-SNAPSHOT

2 years ago

0.0.1-SNAPSHOT

2 years ago