{"library":"openapi-client-axios","title":"OpenAPI Client Axios","description":"openapi-client-axios is a JavaScript and TypeScript library designed to create dynamic API clients from OpenAPI v3 definitions at runtime. It leverages the popular axios library for HTTP requests, offering a powerful and flexible alternative to code generation for API consumption. The current stable version is 7.9.0. The library features automatic TypeScript type generation for API operations, full IntelliSense support, and a consistent API for calling operations using JavaScript methods based on operationIds. It operates isothermically in both browser and Node.js environments. Key differentiators include its no-code-generation approach, strong TypeScript integration, and reliance on existing, robust HTTP client infrastructure (axios), providing a predictable release cadence tied to upstream OpenAPI spec updates and axios releases.","language":"javascript","status":"active","last_verified":"Tue Apr 21","install":{"commands":["npm install openapi-client-axios"],"cli":null},"imports":["import OpenAPIClientAxios from 'openapi-client-axios';","import type { Client } from 'openapi-client-axios';","import type { OpenAPIClient } from 'openapi-client-axios';"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import OpenAPIClientAxios from 'openapi-client-axios';\nimport type { Client } from 'openapi-client-axios';\n\nconst PETSTORE_URL = 'https://petstore.swagger.io/v2/swagger.json';\n\n// Initialize the client with the OpenAPI definition URL\nconst api = new OpenAPIClientAxios({ definition: PETSTORE_URL });\n\nasync function fetchAndCreatePet() {\n  try {\n    // Initialize the API client and get the generated operations\n    const client: Client = await api.getClient();\n\n    // Example 1: Fetch all pets (using a method derived from operationId 'findPetsByStatus')\n    console.log('Fetching available pets...');\n    const availablePetsResponse = await client.findPetsByStatus({ status: ['available'] });\n    console.log('Available pets:', availablePetsResponse.data.slice(0, 3)); // Log first 3\n\n    // Example 2: Create a new pet (using operationId 'addPet')\n    console.log('\\nAdding a new pet...');\n    const newPet = {\n      id: 987654321,\n      name: 'Buddy',\n      status: 'available',\n      category: { id: 1, name: 'Dogs' },\n      photoUrls: ['http://example.com/buddy.jpg']\n    };\n    const addPetResponse = await client.addPet(newPet);\n    console.log('New pet added:', addPetResponse.data);\n\n  } catch (error: any) {\n    console.error('An error occurred:', error.message);\n    if (error.response) {\n      console.error('API Response Data:', error.response.data);\n    }\n  }\n}\n\nfetchAndCreatePet();","lang":"typescript","description":"Initializes an OpenAPI client with a public Petstore definition, then demonstrates fetching existing data and creating new resources using the dynamically generated client methods.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}