-
-
Notifications
You must be signed in to change notification settings - Fork 935
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
Custom options #1794
Comments
We were thinking about asking for a feature like this, but in the end decided not to bother you with this. So yeah, we would appreciate it 😁 I think extending the Options is a more intuitive interface. I would not be sure what the plain extend with getters and setters does without reading the docs. |
No, please, you can ask me anything, I'm more than happy to discuss API improvements :)
I'm thinking the same. This way you can also easily validate the options like this: Lines 934 to 935 in d44b2d2
|
One of the problems is also how to merge custom instances with this. So extending the The first example is counterintuitive as getters are used to retrieve the value, and Got wouldn't know if the getter should be copied to Options or it's just a regular value that Got should execute. So we can solve this in two ways: const instance = got.extend({
custom: {
foobar: prototypeObject
}
}); const instance = got.extend({
custom: ['foobar']
}); To be honest I prefer the last approach. It's the easiest to use, can be easily merged and the normalisation (if necessary) can happen in the |
@szmarczak Are all the options in https://nodejs.org/api/http.html#http_http_request_url_options_callback supported by got or any are incompatible? I remember a note about this in the docs but can't find it anymore in https://github.com/sindresorhus/got/blob/main/documentation/2-options.md. |
Got doesn't support |
@szmarczak Apart from those 2 options, all the other ones in https://nodejs.org/api/http.html#http_http_request_url_options_callback can be provided as |
Some of them yes, some have been renamed, some accept different types. If you're looking for 1:1 then this is not Got. |
const instance = got.extend({
custom: ['foobar']
}); I also think this is a good approach. I assume it will only override the default validation i.e. the above is equivalent to saying "Do not throw when you see a |
Correct. The full solution is already in #1796 but it requires some hilarious TypeScript hacks, it's just not pretty on the TypeScript side but it works as expected (the end types are correct too). I'm ok with it anyway. Eventually we could default all non-Got options to be stored inside |
@szmarczak Not looking for 1:1, the Got interface is nicer.
Could these differences be added to the options documentation? It could help people migrating to Got and even existing users to see a list of all |
Umm... the list would be quite long. It would be better if you'd refer to the documentation directly. |
Got v12 throws when an option does not exist. So the workaround is:
this way
got('...', {token: 'secret'})
will setoptions.context.token
. I think there should be a dedicated API for custom options. Maybe this:or this:
or both?
/cc @sindresorhus @mnmkng
The text was updated successfully, but these errors were encountered: