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

web-api: expose axios interceptors as WebClient constructor option #2073

Closed
mtjandra opened this issue Oct 8, 2024 · 8 comments · Fixed by #2076
Closed

web-api: expose axios interceptors as WebClient constructor option #2073

mtjandra opened this issue Oct 8, 2024 · 8 comments · Fixed by #2076
Labels
auto-triage-skip enhancement M-T: A feature request for new functionality good first issue pkg:web-api applies to `@slack/web-api` semver:minor

Comments

@mtjandra
Copy link
Contributor

mtjandra commented Oct 8, 2024

I'd like to transform outgoing requests from the @slack/web-api package similar to other SDKs such as

This Slack SDK allowa adding additional headers but I require more flexibility. Taking a look at the source it seems it is using axios under the hood (ref). Axios seems to support the concept of interceptors which would support my use case.

I'd like to transform all outgoing requests into POST requests with a body representing the original request, add custom headers, then re-route that to a proxy. Is this possible to configure with the current version @slack/web-api?

If what I'm asking for is not currently possible, is there anything in the works?


Side note: was also thinking we could override the method making the outgoing request (makeRequest), although I'm confused why all outgoing requests are post requests

@filmaj filmaj added question M-T: User needs support to use the project and removed untriaged labels Oct 8, 2024
@filmaj
Copy link
Contributor

filmaj commented Oct 8, 2024

It may be possible in JavaScript, though you'd have to reach in to the private axios instance contained within WebClient, which may be tricky - not sure what the state of the art for ignoring class visibility modifiers is in JS 🤷

Alternatively, this could be a new feature request: expose some option on the WebClient constructor to provide the ability to specify interceptors.

although I'm confused why all outgoing requests are post requests

Because this project is aimed at interacting solely with the Slack HTTP API, and it is designed to accept POST requests for any HTTP API method you wish to interact with, this is a convenient approach for the API client. See this brief overview in our docs for details, in particular:

Pass arguments as POST parameters presented as application/x-www-form-urlencoded
When sending a HTTP POST, you may present your arguments as either standard POST parameters, or you may use JSON instead.

@mtjandra
Copy link
Contributor Author

mtjandra commented Oct 8, 2024

Hi @filmaj thank you for the reply.

you'd have to reach in to the private axios instance contained within WebClient

I would like to avoid overriding and/or modifying private methods/variables as it could lead to unexpected behaviour and breaking changes on version updates.

Alternatively, this could be a new feature request: expose some option on the WebClient constructor to provide the ability to specify interceptors.

Yes it would be amazing if this could be added as a feature. I'm sure other consumers would benefit from this feature as well. It seems fairly common for SDKs to allow consumers to hook into the request life cycle.

@filmaj filmaj added semver:minor good first issue enhancement M-T: A feature request for new functionality pkg:web-api applies to `@slack/web-api` auto-triage-skip and removed question M-T: User needs support to use the project labels Oct 8, 2024
@filmaj filmaj added this to the [email protected] milestone Oct 8, 2024
@filmaj filmaj changed the title How to hook into request lifecycle to transform outgoing requests (@slack/web-api)? web-api: expose axios interceptors as WebClient constructor option Oct 8, 2024
@filmaj
Copy link
Contributor

filmaj commented Oct 8, 2024

OK, I've set it as a feature / enhancement. We cannot promise any delivery timelines for it. However, if this is something you need, we welcome pull requests!

@mtjandra
Copy link
Contributor Author

mtjandra commented Oct 11, 2024

@filmaj I have created a pr: #2076

I've sign the contributor license agreement, but CI is still failing, you may need to re-run the check on your side.

image

Please advise.

@filmaj
Copy link
Contributor

filmaj commented Oct 15, 2024

Closing and re-opening - this sometimes helps reset the CLA robot.

@filmaj filmaj closed this as completed Oct 15, 2024
@filmaj filmaj reopened this Oct 15, 2024
@filmaj
Copy link
Contributor

filmaj commented Oct 15, 2024

I meant to do on the PR, woopsie. Anyways, the CLA check is now resolved. Will review your PR shortly. Thank you for sending it!

@mtjandra
Copy link
Contributor Author

mtjandra commented Oct 23, 2024

@filmaj any idea on when a new release will be published with these changes?

I would love to start making use of it!

@filmaj
Copy link
Contributor

filmaj commented Oct 23, 2024

Just released web-api 7.7.0 on npm and as a GitHub Release!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto-triage-skip enhancement M-T: A feature request for new functionality good first issue pkg:web-api applies to `@slack/web-api` semver:minor
Projects
None yet
2 participants