-
Notifications
You must be signed in to change notification settings - Fork 86
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
Refactor fetchr API #275
Comments
I like the proposal. Some questions:
Would be good to add these details in the proposal. |
Yup, that was intended to be post body data. We could figure out what the correct property name should be (
I think that makes sense, One potential option could be something like this (which basically removes the first param and puts it into the object): fetchr.create({ resource: 'foo', body: {}, params: {}, timeout: 500 }); NOTE: I don't like having
We have them in the readme, the config that gets passed into the
|
I like the idea of moving everything to just one object. In the future, the I see no problem, however, on keeping timeout and etc flattened in the same object. I actually prefer that since it would simplify the process of merging the global configuration and the per request configuration. It would also simplify the From the user perspective, I would also prefer a more flat structure since I could have a module called const baseConfig = {
resource: 'post',
timeout: 3000,
retryStatusCodes: [408, 422, 502]
}
const fetchPosts = (params) => {
const config = { ...baseConfig, params, timeout: 5000, retryAttempts: 2 }
return fetchr.read(config).then().catch()
}
const createPost = (body) => {
const config = { ...baseConfig, body }
return fetchr.create(config).then().catch()
} |
I'm fine with this approach too, we could flatten it too and just have |
By the way, these are all the options that we "support": Global optionsconst fetchr = new Fetchr({
corsPath, // string, path to be used in case clientConfig.cors is true
xhrPath: options.xhrPath, // string, path to be used when clientConfig.cors is false
headers, // object, key/value map of headers
context, // object, that is converted to query params
contextPicker, // string|array|function(value, key, object) to retrieve params from context
xhrTimeout: options.xhrTimeout, // number, request timeout
statsCollector, // function, hook to run after every request
}); Per request optionsconst clientConfig = {
uri, // string, if set, overrides global cors/xhr paths
constructGetUri, // function, to generate the final url
id_param, // string, sets the param that is used as id, constructGetUri will set it in the url if present
headers, // object, if set, overrrides global headers
post_for_read, // bool, use POST for read operation
timeout, // number, request timeout value
xhrTimeout, // number, same as timeout
cors, // bool, decides if it's going to use xhr or xdr path
withCredentials, // bool, if should include cookies on cors requests
useXDR, // bool, if it should use XDR instead of XHR (currently there is a bug that this is impossible to be set, but since xdr is dead...)
unsafeAllowRetry, // bool, allow retry for POST requests
retry: {
interval, // number, interval btw attempts
maxRetries, // number, max number of attempts
statusCodes, // array, http status codes allowed for retries
},
}; |
Mix of case style is disappointing, might make those all camelcase too. |
My proposal: const proposal = {
path, // string, replaces xhrPath, corsPath and uri
urlBuilder, // function, replaces constructGetUri
headers,
context, // object|function, replaces contextPicker
timeout,
statsCollector,
usePostOnRead, // bool, replaces post_for_read
withCredentials,
retryAttempts, // number, replaces retry.maxRetries
retryInterval, // number, replaces retry.interval
retryOnPost, // bool, replaces unsafeAllowRetry
retryStatusCodes, // array, replaces retry.statusCodes
}; |
I like having xhrPath, coresPath and uri being combined, makes it simple without a ton of different options. One question is what if const fetcher = new Fetcher({
corsPath: 'http://www.foo.com',
xhrPath: '/fooProxy',
}); |
I would then rename it to Currently it's either one or another: https://github.com/yahoo/fetchr/blob/master/libs/fetcher.client.js#L236 and they are never concatenated. Since |
Besides changing the request object, I think it would be very cool if we could let the users name the operations. We could use POST by default and add an useGET option to change to GET. In this way we could make fetchr super flexible: Fetcher.registerResource('todo', {
readItem: function () {},
readList: function() {},
toggle: function() {},
delete: function() {},
archive: function() {},
}); Also, we could add a meta param to the register function with arbitrary data. This data could be used in a middleware (for example, a documentation route that lists all resources and their operations): Fetchr.registerResource('todo', operations, {
upstreamService: 'todo-v1',
usesDb: false,
shouldCache: true,
// ...
}); |
I'm fine with the |
@redonkulus Is this possible right now? |
@pablopalacios Ya its just an implementation detail for the fetchr class. |
@snyamathi @lingyan @pablopalacios
Goal
Make the API more intuitive and easy to use for developers
Background
Some of this work is based on the discussion in #263 (comment)
Proposals
Simplify CRUD signatures
end
call or the doublenull
).callback
interfaceend()
methodCurrent:
Proposal:
The text was updated successfully, but these errors were encountered: