1.0.0 • Published 3 years ago

waterloo-lookup-fetcher v1.0.0

Weekly downloads
-
License
MIT
Repository
-
Last release
3 years ago

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();
1.0.0

3 years ago