@faasjs/browser

FaasJS browser client.

If you use React or Vue, please use @faasjs/reactopen in new window or @faasjs/vue-pluginopen in new window.

License: MITopen in new windowNPM Stable Versionopen in new windowNPM Beta Versionopen in new window

Browser plugin for FaasJS.

Install

npm install @faasjs/browser

Use directly

import { FaasBrowserClient } from '@faasjs/browser'

const client = new FaasBrowserClient('/')

await client.action('func', { key: 'value' })

Use with SWR

import { FaasBrowserClient } from '@faasjs/browser'
import useSWR from 'swr'

const client = new FaasBrowserClient('/')

const { data } = useSWR(['func', { key: 'value' }], client.action)

Reference: Data Fetching - SWRopen in new window

Use with React Query

import { FaasBrowserClient } from '@faasjs/browser'
import { QueryClient } from 'react-query'

const client = new FaasBrowserClient('/')

const queryClient = new QueryClient({
  defaultOptions: {
    queries: {
      queryFn: async ({ queryKey }) => client
        .action(queryKey[0] as string, queryKey[1] as any)
        .then(data => data.data),
    },
  },
})

function App() {
  return (
    <QueryClientProvider client={queryClient}>
      <YourApp />
    </QueryClientProvider>
  )
}

Reference: Default Query Function | TanStack Queryopen in new window

Modules

Classes

Type Aliases

Type Aliases

FaasBrowserClientAction

Ƭ FaasBrowserClientAction: <PathOrData>(action: PathOrData | string, params?: FaasParams<PathOrData>, options?: Options) => Promise<Response<FaasData<PathOrData>>>

Type declaration

▸ <PathOrData>(action, params?, options?): Promise<Response<FaasData<PathOrData>>>

Type parameters
NameType
PathOrDataextends FaasAction
Parameters
NameType
actionPathOrData | string
params?FaasParams<PathOrData>
options?Options
Returns

Promise<Response<FaasData<PathOrData>>>


Options

Ƭ Options: RequestInit & { beforeRequest?: ({ action, params, options }: { action: string ; options: Options ; params: Record<string, any> }) => Promise<void> | void ; headers?: { [key: string]: string; } ; request?: <PathOrData>(url: string, options: Options) => Promise<Response<FaasData<PathOrData>>> }


ResponseHeaders

Ƭ ResponseHeaders: Object

Index signature

▪ [key: string]: string