Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
3 changes: 2 additions & 1 deletion src/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand Down
4 changes: 3 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
useSetUp,
useDataDiscovery,
useExecuteQuery,
useFetcher
} from './hooks';

import {
Expand All @@ -19,5 +20,6 @@ export {
SlashDBConsumer,
useSetUp,
useDataDiscovery,
useExecuteQuery
useExecuteQuery,
useFetcher
};