XFarr API Wrapper
xfarr-api is a JavaScript/TypeScript module providing a full implementation of the `api.xfarr.com` REST API, designed for use in Node.js environments. It currently stands at version 3.0.1, indicating active development, though a specific release cadence is not detailed. The library acts as a client for various web scraping and utility features exposed by the xfarr.com service, such as 'stalking' npm package information. Its primary differentiator is providing a structured, promise-based interface to a third-party API, simplifying interaction and abstracting HTTP requests, requiring an API key for all operations.
Common errors
-
Error: Unauthorized
cause The provided API key is invalid, expired, or missing in the request.fixEnsure you are using a correct and active API key. Double-check for typos and confirm it has not expired on the xfarr.com dashboard. Pass the key to the `APIWrapper` constructor: `new APIWrapper('YOUR_API_KEY')`. -
xfar.[feature].[name] is not a function
cause Attempting to call a non-existent feature or method, or the API feature may have been removed or renamed.fixConsult the latest `xfarr-api` documentation or the `api.xfarr.com` documentation to verify the correct feature and method names. Ensure you are using a supported version of the library. -
TypeError: APIWrapper is not a constructor
cause The `APIWrapper` class was not instantiated with the `new` keyword.fixAlways create an instance of the wrapper using `new APIWrapper(apiKey);` before attempting to call its methods.
Warnings
- gotcha An API key is strictly required for all interactions with the xfarr.com API. Operations will fail without a valid key.
- gotcha The underlying xfarr.com API may have rate limits or usage quotas. Exceeding these limits can lead to temporary or permanent blocking of your API key.
- gotcha As a wrapper around a third-party API, `xfarr-api`'s functionality is dependent on the stability and feature set of `api.xfarr.com`. Changes to the upstream API could introduce breaking changes not reflected in the `xfarr-api`'s major version bumps.
Install
-
npm install xfarr-api -
yarn add xfarr-api -
pnpm add xfarr-api
Imports
- APIWrapper
import { APIWrapper } from 'xfarr-api';import APIWrapper from 'xfarr-api';
- APIWrapper
const { APIWrapper } = require('xfarr-api');const APIWrapper = require('xfarr-api'); - APIWrapperType
import { APIWrapperType } from 'xfarr-api';import type { APIWrapperType } from 'xfarr-api';
Quickstart
import APIWrapper from 'xfarr-api';
const API_KEY = process.env.XFARR_API_KEY ?? ''; // Ensure your API key is set as an environment variable
if (!API_KEY) {
console.error('Error: XFARR_API_KEY environment variable is not set.');
process.exit(1);
}
const xfar = new APIWrapper(API_KEY);
// Example of an API call: fetching npm package information
xfar.stalking.npmjs("xfarr-api")
.then(response => {
console.log('NPM Stalking Result:', response);
})
.catch(error => {
console.error('Error during NPM stalking:', error.message);
});
// Another example: (assuming 'random' feature exists and takes no params)
xfar.random.meme()
.then(response => {
console.log('Random Meme:', response);
})
.catch(error => {
console.error('Error fetching random meme:', error.message);
});