@faasjs/browser
FaasJS browser client.
If you use React or Vue, please use @faasjs/react or @faasjs/vue-plugin.
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 - SWR
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 Query
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
Name | Type |
---|---|
PathOrData |
extends FaasAction
|
Parameters
Name | Type |
---|---|
action |
PathOrData | 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
string
]: string