Releases: yahoo/fetchr
Promise Support and misc refactor
#115 - Add promise support to fetchr
// Before
fetcher
.read('data_api_service')
.params({id: ###})
.end(function (err, data) {
// data is returned by `data_api_service`
});
//After
fetcher
.read('data_api_service')
.params({id: ###})
.end()
.then(function (result) {
// result.data is returned by `data_api_service`
});
#122 - Refactor service metadata
Metadata logic in fluxible-plugin-fetchr
has been moved into fetchr
itself. The usage is the same as before.
// callback
fetcher
.read('data_api_service')
.params({id: ###})
.end(function (err, data, meta) {
// meta will contain any headers returned by the `data_api_service`
});
// promise
fetcher
.read('data_api_service')
.params({id: ###})
.end()
.then(function (result) {
// result.meta will contain any headers returned by the `data_api_service`
});
Context picker support
#121 - Provide additional options contextPicker
to determine how to pick the context values as parts of uri queries
Bugfix: Don't cast big integers into Numbers
-
#120 Don't cast big integers into Number type
Fetcher middleware receives all params as strings. It then, tries to cast these strings into their primitive types. However, numbers larger than MAX_SAFE_INTEGER were being rounded incorrectly introducing errors(See #119). The fix is to just leave these big integers as strings and let the user convert them as needed.
Added ability to return more information in error object
Thanks @KATT for the contribution!
An additional output
property can be added to the error object to return addition information when an error occurs.
Provide function to update options
#114 - provide function to update options
Interface Changes
#110 - New CRUD interface
We're deprecating the old interface:
fetcher.read('resource', {id: ###}, {}, function (err, data, meta) {
// handle err and/or data returned from data fetcher in this callback
});
in favor of a cleaner, chainable, interface:
fetcher
.read('resource')
.params({id: ###})
.end(function (err, data, meta) {
// handle err and/or data returned from data fetcher in this callback
});
Few things to keep in mind:
- Always start fetcher requests with one of the CRUD (
create
,read
,update
, ordelete
) methods. - Then chain with
params
,body
, orclientConfig
in any order. - Always end requests with the
end
method and provide a callback.
Note: This release does not affect how your data services are defined, it just provides a new way to access your services.