{"library":"purest","title":"Purest REST API Client","description":"Purest is a flexible JavaScript library for constructing expressive REST API clients, abstracting away the low-level HTTP request details. It enables developers to define detailed API configurations, including base URLs, paths, headers, and versioning, for various service providers. The library then facilitates interaction through a fluent, chainable API that supports custom query parameters, authentication, and HTTP methods, with options for preconfigured defaults and method aliases. Currently in stable version 4.0.3, Purest is actively maintained, supporting Node.js environments (>=12.0.0) and ships with TypeScript types for improved developer experience. It relies on the `request-compose` library for its underlying HTTP capabilities. Purest differentiates itself by providing a highly configurable and declarative approach to API consumption, allowing for complex API structures to be represented and interacted with in an abstract yet powerful manner, making it suitable for managing interactions with multiple, diverse REST APIs within a single application.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install purest"],"cli":null},"imports":["import purest from 'purest'","import type { PurestClient } from 'purest'"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import purest from 'purest';\n\nconst config = {\n  \"google\": {\n    \"default\": {\n      \"origin\": \"https://www.googleapis.com\",\n      \"path\": \"{path}\",\n      \"headers\": {\n        \"authorization\": \"Bearer {auth}\"\n      }\n    },\n    \"youtube\": {\n      \"origin\": \"https://www.googleapis.com\",\n      \"path\": \"youtube/{version}/{path}\",\n      \"version\": \"v3\",\n      \"headers\": {\n        \"authorization\": \"Bearer {auth}\"\n      }\n    }\n  }\n};\n\nasync function getYouTubeChannels(username: string, token: string) {\n  const google = purest({ provider: 'google', config });\n\n  try {\n    const { res, body } = await google('youtube')\n      .get('channels')\n      .qs({ forUsername: username })\n      .auth(token)\n      .request();\n\n    console.log('Status:', res.statusCode);\n    console.log('Body:', JSON.stringify(body, null, 2));\n    return body;\n  } catch (error) {\n    console.error('Error fetching YouTube channels:', error);\n    throw error;\n  }\n}\n\n// Example usage: replace with your actual Google API token and desired username\nconst GOOGLE_AUTH_TOKEN = process.env.GOOGLE_AUTH_TOKEN ?? 'YOUR_GOOGLE_AUTH_TOKEN';\nconst TARGET_USERNAME = 'GitHub'; \n\nif (GOOGLE_AUTH_TOKEN === 'YOUR_GOOGLE_AUTH_TOKEN') {\n    console.warn(\"Please set GOOGLE_AUTH_TOKEN environment variable or replace 'YOUR_GOOGLE_AUTH_TOKEN' with an actual token to run this example.\");\n} else {\n    getYouTubeChannels(TARGET_USERNAME, GOOGLE_AUTH_TOKEN)\n        .then(() => console.log(`Attempted to fetch YouTube channels for ${TARGET_USERNAME}.`))\n        .catch(() => console.error('Failed to execute YouTube channel fetch example.'));\n}","lang":"typescript","description":"This example demonstrates how to configure a Purest client for Google's YouTube API, apply an authentication token, query for channels by username, and execute the request.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}