Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interceptors #490

Open
joseglego opened this issue May 10, 2022 · 1 comment · May be fixed by #619
Open

Interceptors #490

joseglego opened this issue May 10, 2022 · 1 comment · May be fixed by #619
Assignees
Labels
priority: p3 Desirable enhancement or fix. May not be included in next release. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.

Comments

@joseglego
Copy link

Is your feature request related to a problem? Please describe.
When using gaxios in my project to connect to Google services, but also to third-party services. I'm connecting to APIS which uses different syntaxis for communication (for example, snake_case) and I'm using camelCase in my project. So, every time I do a request I have to decamelize (transform into snake_case) and when receiving the information I have to camelize it (transform into camelCase)

In general, I'd like to extend gaxios to handle all the requests. So, I don't have to have multiple libraries to do the same.

Describe the solution you'd like
I have used axios previously, and the solution which I found in that tool was being able to create interceptors to responses, but also to requests:

// Add a request interceptor
axios.interceptors.request.use(function (config) {
    // Do something before request is sent
    return config;
  }, function (error) {
    // Do something with request error
    return Promise.reject(error);
  });

// Add a response interceptor
axios.interceptors.response.use(function (response) {
    // Any status code that lie within the range of 2xx cause this function to trigger
    // Do something with response data
    return response;
  }, function (error) {
    // Any status codes that falls outside the range of 2xx cause this function to trigger
    // Do something with response error
    return Promise.reject(error);
  });

More info: https://github.com/axios/axios#interceptors
Describe alternatives you've considered
Create one small library/util which will work as a wrap to gaxios, which would process (camelize the data) but also decamelize the response.

Additional context
I have found already this issue:
#181
and read the implementation:
https://github.com/googleapis/gaxios/pull/319/files

but what I noticed is, that adapters are ONLY working for response and not for requests.

@joseglego joseglego added priority: p3 Desirable enhancement or fix. May not be included in next release. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design. labels May 10, 2022
@geroale
Copy link

geroale commented Aug 30, 2022

I have the same necessity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: p3 Desirable enhancement or fix. May not be included in next release. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants