diff --git a/README.md b/README.md index f272006..e533d4f 100644 --- a/README.md +++ b/README.md @@ -278,3 +278,14 @@ const [queryData, execQuery] = useExecuteQuery( **Return value ```queryData```** – an array containing the data retrieved from the query. The data can be used like any JS array. **Return value ```execQuery```** - ```execQuery(params, body, httpMethod = undefined, headers = undefined)``` - a function to execute the query passed to ```useExecuteQuery```. Takes a ```params``` object containing key/value pairs of parameters. Also accepts a ```body``` parameter, for queries that are configured to use POST/PUT methods. Note that when executing a query with the POST method, the ```params``` object will be ignored. Setting ```httpMethod``` will override the ```defHttpMethod``` given to ```useExecuteQuery``` when calling this function - this value should be one of GET/POST/PUT/DELETE. Finally, a ```headers``` object of key/value pairs representing HTTP request headers can be passed along with the request. + +### useFetcher(instanceName = 'default') + +```useFetcher``` enables the creation of requests to custom paths in cases that custom endpoint and query parameters are required. This fet + +```jsx +const fetcher = useFetcher(); +const data = await fetcher("/db/database/table.json?limit=10&transpose"); +``` + +**Return value ```fetcher```** – a wrapper of fetch that includes SlashDB credentials after a successfull login. If no login was performed, `public` user will be used by default. diff --git a/src/hooks.js b/src/hooks.js index dc53f59..88ae573 100644 --- a/src/hooks.js +++ b/src/hooks.js @@ -92,7 +92,8 @@ const useFetcher = (instanceName = 'default') => { return update; } - function fetcher(url, options = {}){ + function fetcher(path, options = {}){ + const url = sdbClient.sdbConfig._buildEndpointString(path); return fetch(url, updateOptions(sdbClient, options)); } diff --git a/src/index.js b/src/index.js index 0946a2e..870a2c9 100644 --- a/src/index.js +++ b/src/index.js @@ -4,6 +4,7 @@ import { useSetUp, useDataDiscovery, useExecuteQuery, + useFetcher } from './hooks'; import { @@ -19,5 +20,6 @@ export { SlashDBConsumer, useSetUp, useDataDiscovery, - useExecuteQuery + useExecuteQuery, + useFetcher };