hey-api / openapi-ts

✨ Turn your OpenAPI specification into a beautiful TypeScript client

Home Page:https://heyapi.vercel.app

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Expose `url` in request interceptor object for fetch client

jskovman opened this issue · comments

Description

When using interceptors with client fetch (and node, and possibly others) in the configuration, the url prop is not present in the request object passed in the callback function.

It would be useful to include the url as a prop/parameter to the request interceptor for fetch/node, similar to the axios request object – if only for request logging purposes, but likely other use cases as well.

// Using client "fetch"
OpenAPI.interceptors.request.use((request) => {
  console.log(request.url); // ❌ `request.url` is undefined
  return request;
});

When using client axios, url is present:

// Using client "axios"
OpenAPI.interceptors.request.use((request) => {
  console.log(request.url); // ✅ `request.url` is defined
  return request;
});

Yep I agree with this @jskovman, we need to figure out a cleaner API for interceptors!

commented

@jskovman this is available in the Fetch API client. You can view the demo and play with the interceptor, both arguments have URLs. Would love to hear your thoughts!