From 9048de6eed48512572148ab366c1e9bd5386b2b9 Mon Sep 17 00:00:00 2001 From: Nelson Carrasquel Date: Tue, 27 Aug 2024 09:36:19 -0400 Subject: [PATCH 1/2] include useFetcher in index.js export --- src/index.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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 }; From bf47205713cd12483efe9a1f69863887db1371d6 Mon Sep 17 00:00:00 2001 From: Nelson Carrasquel Date: Tue, 27 Aug 2024 10:02:13 -0400 Subject: [PATCH 2/2] url changed for path --- README.md | 11 +++++++++++ src/hooks.js | 3 ++- 2 files changed, 13 insertions(+), 1 deletion(-) 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)); }