Legacy Clients ​
Before client packages, clients were generated using @hey-api/openapi-ts
. In fact, @hey-api/openapi-ts
still supports generating legacy clients. You can generate them with the client
config option.
export default {
client: 'legacy/fetch',
input: 'path/to/openapi.json',
output: 'src/client',
};
export default {
client: 'legacy/axios',
input: 'path/to/openapi.json',
output: 'src/client',
};
export default {
client: 'legacy/angular',
input: 'path/to/openapi.json',
output: 'src/client',
};
export default {
client: 'legacy/node',
input: 'path/to/openapi.json',
output: 'src/client',
};
export default {
client: 'legacy/xhr',
input: 'path/to/openapi.json',
output: 'src/client',
};
Available Clients ​
Caveats ​
Please be aware that legacy clients are missing some key features:
- no type-safe errors 🚫
- no access to the original request and response 🚫
- hard to configure individual requests 👎
- inconsistent interceptors and response APIs 👎
TIP
You might not need a node
client. Fetch API is experimental in Node.js v18 and stable in Node.js v21. We recommend upgrading to the latest Node.js version.
Interceptors ​
Interceptors (middleware) can be used to modify requests before they're sent or responses before they're returned to the rest of your application.
Below is an example request interceptor
OpenAPI.interceptors.request.use((request) => {
doSomethingWithRequest(request);
return request; // <-- must return request
});
OpenAPI.interceptors.request.eject((request) => {
doSomethingWithRequest(request);
return request; // <-- must return request
});
and an example response interceptor
OpenAPI.interceptors.response.use(async (response) => {
await doSomethingWithResponse(response); // async
return response; // <-- must return response
});
OpenAPI.interceptors.response.eject(async (response) => {
await doSomethingWithResponse(response); // async
return response; // <-- must return response
});
TIP
To eject, you must provide the same function that was passed to use()
.
WARNING
Angular client does not currently support request interceptors.
Examples ​
You can view live examples on StackBlitz.
Sponsors ​
Love Hey API? Become our sponsor.