UNPKG

waterloo-lookup-fetcher

Version:

Lookup fetcher

63 lines (47 loc) 1.6 kB
# dcsl-lookup-fetcher **dcsl-lookup-fetcher** is a library to consume API end points **Example usage** ```JAVASCRIPT 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 ```JAVASCRIPT 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 ```JAVASCRIPT 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 ```JAVASCRIPT 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(); ```