{"id":48770398,"url":"https://github.com/CERN/react-openapi-generator-hook","last_synced_at":"2026-04-29T07:00:59.949Z","repository":{"id":288590880,"uuid":"880313845","full_name":"CERN/react-openapi-generator-hook","owner":"CERN","description":"OpenApi Generator provides an implementation of the functions and the model necessary to call HTTP endpoints. This repository aims to streamline the configuration of the tool and provides a hook to perform HTTP calls and handle responses efficently.","archived":false,"fork":false,"pushed_at":"2025-08-25T19:42:44.000Z","size":358,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-08-25T20:28:10.499Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/CERN.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2024-10-29T13:59:48.000Z","updated_at":"2025-06-02T18:29:58.000Z","dependencies_parsed_at":"2025-04-19T00:49:13.674Z","dependency_job_id":"684e393a-4dc2-4f32-9591-bf16edddba23","html_url":"https://github.com/CERN/react-openapi-generator-hook","commit_stats":null,"previous_names":["stefanomarzo/react-openapi-generator-hook","cern/react-openapi-generator-hook"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/CERN/react-openapi-generator-hook","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CERN%2Freact-openapi-generator-hook","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CERN%2Freact-openapi-generator-hook/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CERN%2Freact-openapi-generator-hook/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CERN%2Freact-openapi-generator-hook/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/CERN","download_url":"https://codeload.github.com/CERN/react-openapi-generator-hook/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CERN%2Freact-openapi-generator-hook/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32414422,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-29T06:29:02.080Z","status":"ssl_error","status_checked_at":"2026-04-29T06:29:00.631Z","response_time":110,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-04-13T10:00:21.753Z","updated_at":"2026-04-29T07:00:59.944Z","avatar_url":"https://github.com/CERN.png","language":"TypeScript","funding_links":[],"categories":["Libraries"],"sub_categories":["UI"],"readme":"\u003c!--\nSPDX-FileCopyrightText: 2025 CERN\n\nSPDX-License-Identifier: MIT\n--\u003e\n\n# `react-openapi-generator-hook`\n\nA lightweight React hook utility for calling API methods generated from OpenAPI specifications. Simplify your frontend API integration by using a consistent, declarative hook-based approach — without manually instantiating and managing API clients.\n\n## 🚀 Features\n\n* ⚛️ React-first API interaction with minimal boilerplate\n* 🔄 Built-in support for async states: `loading`, `data`, and `error`\n* ⚙️ Support for multiple API configurations and endpoints\n* ✅ Compatible with OpenAPI Generator's generated `*ApiFactory` functions\n\n## 🧩 Installation\n\n```bash\nnpm install react-openapi-generator-hook\n```\n\n## 🛠️ Basic Usage\n\n```tsx\nimport { useApi, OpenApiProvider } from 'react-openapi-generator-hook'\nimport { PetApiFactory, Configuration } from './generated'\nimport axios from 'axios'\n\n// Setup config\nconst axiosInstance = axios.create({ withCredentials: true }) // custom headers here\nconst configMap = {\n  PETS: {\n    axiosInstance,\n    configuration: new Configuration({ accessToken: '1234567890' }),\n    baseUrl: 'https://petstore3.swagger.io/api/v3',\n  },\n  USERS: {\n    axiosInstance,\n    configuration: new Configuration({ accessToken: '0123456789' }),\n    baseUrl: 'https://users.cern.ch/api/v3',\n  }\n}\n\n// Wrap your app or your components\n\u003cOpenApiProvider defaultConfigurationId=\"PETS\" openApiConfigurationMap={configMap}\u003e\n  \u003cApp /\u003e\n\u003c/OpenApiProvider\u003e\n```\nWithin your component\n```tsx\n// E.g. PetComponent.tsx\nconst [{ data, error, loading }, fetchPet] = useApi({\n  apiFactory: PetApiFactory,\n  methodName: 'getPetById',\n  requestParameters: 4,\n})\n\nreturn (\n  \u003cdiv\u003e\n    {loading \u0026\u0026 'Loading...'}\n    {error \u0026\u0026 \u003cdiv\u003eError: {error.message}\u003c/div\u003e}\n    {data \u0026\u0026 \u003cdiv\u003ePet name: {data.name}\u003c/div\u003e}\n  \u003c/div\u003e\n)\n```\n\n## 📦 API\n\n### `useApi`\n\nA custom hook for invoking a specific API method from an OpenAPI-generated factory.\n\n**Parameters:**\n\n```ts\n{\n  apiFactory: (config: Configuration) =\u003e any,     // The API factory to use\n  methodName: string,                             // Name of the method to invoke\n  requestParameters?: any,                        // Parameters to pass to the method\n},\n{\n  manual?: boolean                                // if true, does not send request on component mount\n  configurationId?: string                        // (Optional) Configuration key to use\n}\n```\n\n**Returns:**\n\n```ts\n[\n  { data, error, loading },  // Result state\n  refetch                    // Function to manually re-trigger the call\n]\n```\n\n### `OpenApiProvider`\n\nA context provider that supplies configuration for all `useApi` calls.\n\n**Props:**\n\n* `defaultConfigurationId: string` – (optional) the default API to use\n* `openApiConfigurationMap: Record\u003cstring, OpenApiConfigurationType\u003e` – a map of configurations:\n\n    * `axiosInstance`: Axios instance to use\n    * `configuration`: OpenAPI `Configuration` object (with accessToken, etc.)\n    * `baseUrl`: Base URL of the API\n\n\nYou can also extend this setup to dynamically refresh tokens or inject headers as needed via `axios`.\n\n## 🧪 Example Project\n\nA guided example project showing how to use the hook is available here:\n👉 [react-openapi-generator-hook-demo](./examples/demo)\n\n## 🧱 Built With\n\n* [React](https://reactjs.org)\n* [Axios](https://axios-http.com)\n* [OpenAPI Generator](https://openapi-generator.tech/)\n\n## 📃 License\n\nMIT © CERN\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FCERN%2Freact-openapi-generator-hook","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FCERN%2Freact-openapi-generator-hook","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FCERN%2Freact-openapi-generator-hook/lists"}