waterloo-lookup-fetcher
v1.0.0
Published
Lookup fetcher
Downloads
60
Readme
dcsl-lookup-fetcher
dcsl-lookup-fetcher is a library to consume API end points
Example usage
import { LookupFetcher } from 'dcsl-lookup-fetcher';
// This will create 'lookups' object at vueInstance
// and an array 'Users' containing the result from calling 'api/User'
new LookupFetcher(vueInstance).Name('Users').Api('User').Fetch();
Passing parameters
import { LookupFetcher } from 'dcsl-lookup-fetcher';
// You can pass params just appending them to 'Api' string
new LookupFetcher(vueInstance).Name('Users').Api('User/' + id).Fetch();
// Or you can pass second object which will be appended to the query string
// api/users?ascending=1&page=1&page=1
new LookupFetcher(vueInstance)
.Name('Users')
.Api('User', { ascending: 1, page: 1, page: 1 })
.Fetch();
Selecting fields we want
import { LookupFetcher } from 'dcsl-lookup-fetcher';
// By default 'dcsl-lookup-fetcher' expects 'id' and 'name'
// but we can pass an array with what fields we want
new LookupFetcher(vueInstance)
.Name('Users')
.Fields(['id', 'firstname', 'lastname', 'age', 'address'])
.Fetch();
After fetch callback
import { LookupFetcher } from 'dcsl-lookup-fetcher';
// We can attach an callback function to 'AfterFetch'
// It returns single parameter, array with all the records
new LookupFetcher(vueInstance)
.Name('Users')
.Fields(['id', 'firstname', 'lastname', 'age', 'address'])
.AfterFetch((records) => {
// Some custom logic here...
}
.Fetch();