Giter Site home page Giter Site logo

angelxmoreno / rapidapi-node-sdk Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 253 KB

An open-source Node.js SDK for interacting with RapidAPI’s diverse set of APIs, featuring built-in caching for improved performance.

License: MIT License

Shell 1.15% TypeScript 98.85%

rapidapi-node-sdk's Introduction

RapidAPI Node SDK

Maintainability Test Coverage codecov Build on Main License Last Commit dependencies

An open-source Node.js SDK for interacting with RapidAPI’s diverse set of APIs, featuring built-in caching for improved performance.

Installation

npm install rapidapi-node-sdk

or

yarn add rapidapi-node-sdk

Usage

import { RapidApi } from 'rapidapi-node-sdk';

const rapidApi = new RapidApi({
    rapidApiKey: 'your-rapidapi-key',
    rapidApiHost: 'api.rapidapi.com',
    baseUrl: 'https://api.example.com',
});

Making API Calls

const response = await rapidApi.call({
    method: 'get',
    uri: '/endpoint',
    params: { foo: 'bar' },
});

Logging

The SDK supports logging to capture information about API requests. You can enable logging by providing a logger when creating the RapidApi instance:

import { RapidApi, Logger } from 'rapidapi-node-sdk';

// Example using console as a logger
const rapidApiWithLogger = new RapidApi({
    rapidApiKey: 'your-rapidapi-key',
    rapidApiHost: 'api.rapidapi.com',
    baseUrl: 'https://api.example.com',
    logger: console, // Use console.log as a simple logger
});

Compatible Loggers

The SDK is compatible with various logging libraries, including:

  • Pino
  • Winston
  • Bunyan

To use a custom logger, make sure it adheres to the following interface:

export interface Logger {
    info(message: string, data?: Record<string, unknown>): void;
}

Example using Pino as a logger:

import { RapidApi, Logger } from 'rapidapi-node-sdk';
import pino from 'pino';

const logger: Logger = pino();

const rapidApiWithCustomLogger = new RapidApi({
    rapidApiKey: 'your-rapidapi-key',
    rapidApiHost: 'api.rapidapi.com',
    baseUrl: 'https://api.example.com',
    logger: logger,
});

Choose the logger that best fits your application needs, ensuring it conforms to the specified interface.

Caching

The SDK uses Keyv to provide built-in caching, optimizing API requests and improving performance. If you want to use the default in-memory cache provided by the SDK, there's no need to install Keyv separately. However, if you wish to use a different caching adapter, you would need to install it separately. For a list of different caching adapters, please refer to the Keyv npm package.

Caching Usage

import { RapidApi } from 'rapidapi-node-sdk';
import Keyv from 'keyv';

// Create a new RapidApi instance with caching using the default in-memory cache
const rapidApiWithCaching = new RapidApi({
    rapidApiKey: 'your-rapidapi-key',
    rapidApiHost: 'api.rapidapi.com',
    baseUrl: 'https://api.example.com',
    cache: new Keyv(), // Use default in-memory cache
});

Issues

If you encounter any issues or have suggestions, please report them here.

Contributing

Contributions are welcome! Please read CONTRIBUTING.md for details on our code of conduct and the process for submitting pull requests.

License

This project is licensed under the MIT License - see the LICENSE file for details.

rapidapi-node-sdk's People

Contributors

angelxmoreno avatar

Watchers

 avatar  avatar

rapidapi-node-sdk's Issues

no dist/index.js file

to use the class in a project, one has to import it via

import { RapidApi } from 'rapidapi-node-sdk/dist/RapidApi';

This is due to the package.json file stating the main file is dist/indx.js but none is generated.

Doc typo

the import for Keyv should be

import Keyv from 'keyv';

Add parameter validation to RapidApi class constructor

This issue tracks the enhancement to add parameter validation for , , and in the class constructor, as discussed in PR #3 and specifically in this comment: #3 (comment)

Adding these validations will ensure that the class is instantiated with all necessary configuration parameters, preventing runtime errors related to missing configurations.

Implement Global Error Handler for Axios Instance in RapidApi Class

As discussed in PR #1 and this comment, there's a need to implement a global error handler for the Axios instance used in the class. This enhancement aims to ensure graceful handling of HTTP request failures across the application.

The implementation should follow the suggested approach of using Axios interceptors for error handling, as outlined in the discussion. This ticket serves to track the enhancement for future development.

@angelxmoreno, please review the issue details and adjust as necessary.

cache keys for different domains

currently, cache keys do not take into consideration the baseUrl for generating cache keys. This means that to identical calls to different domains yield the same cache key

Enhance method to handle in request body for requests

The method in the class currently constructs the correctly but does not account for cases where the might need to be in the request body for requests, as highlighted in this PR comment. This issue aims to adjust the method to handle in the request body for requests appropriately and to investigate what happens when an API expects instead of .

Related PR: #3

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.