Skip to content

Add option to specify fetch function per request #33

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

half2me
Copy link

@half2me half2me commented Jul 13, 2021

This adds the option to specify what function to use for fetch requests.
Itt adds compatibility for using AppSearch in SvelteKit load functions

Backwards compatible, but allows to specify a custom fetch function per request.

const fetchFn = require('node-fetch')
const result = await client.search(query.get('q'), options, fetchFn)

Or uses the globally available fetch if not specified:

const result = await client.search(query.get('q'), options)

Example usage in SvelteKit load function:

// index.svelte

<script context="module">
import { createClient } from '@elastic/app-search-javascript'
const client = createClient({})

export const load = async ({ fetch }) => {
  const result = await client.search('foo', {}, fetch)
  return { props: { result } }
}
</script>

<script>
export let result
</script>

<pre>
  {JSON.stringify(result, null, 2)}
</pre>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant