{"library":"micro-api-client","title":"Micro REST API Client","description":"This is a compact, promise-based REST API client specifically designed for streamlined interaction with 'micro REST APIs.' It leverages the native `fetch` API for making HTTP requests, simplifying data retrieval from JSON endpoints. The current stable version is 3.3.0, indicating active maintenance with recent patch releases. Key differentiators include its minimal footprint, a clear focus on lightweight API interactions (distinct from comprehensive enterprise API clients), and built-in functionality for handling pagination within JSON responses. The library also provides specialized error types, `HTTPError`, `TextHTTPError`, and `JSONHTTPError`, to facilitate robust error handling. It is designed to be compatible with both browser environments and Node.js, although Node.js usage typically requires a `fetch` polyfill.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install micro-api-client"],"cli":null},"imports":["import API from 'micro-api-client'","import { getPagination } from 'micro-api-client'","import { JSONHTTPError } from 'micro-api-client'"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import API, { JSONHTTPError } from 'micro-api-client';\n\n// For Node.js environments, you might need a fetch polyfill:\n// import fetch from 'node-fetch';\n// global.fetch = fetch;\n\nconst api = new API('/api/v1', {\n  defaultHeaders: {\n    'Authorization': `Bearer ${process.env.API_KEY ?? ''}`\n  }\n});\n\nasync function fetchData() {\n  try {\n    const response = await api.request('posts', {\n      method: 'GET',\n      headers: { 'X-Custom-Header': 'Hello' }\n    });\n    \n    // Check if the response has pagination info\n    if (response.pagination && response.items) {\n      console.log('Paginated items:', response.items);\n      console.log('Pagination info:', response.pagination);\n    } else {\n      console.log('Response data:', response);\n    }\n  } catch (err) {\n    if (err instanceof JSONHTTPError) {\n      console.error('API Error (JSON):', err.json);\n      console.error('Status:', err.status);\n    } else if (err.status) {\n      console.error('HTTP Error:', err.status, err.message);\n    } else {\n      console.error('An unexpected error occurred:', err);\n    }\n  }\n}\n\nfetchData();","lang":"typescript","description":"Demonstrates instantiating the API client, making a GET request, and handling different types of API errors, including JSONHTTPError and generic HTTP errors. Includes a placeholder for Node.js fetch polyfill.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}