The 4 clients represent the 4 authentication methods available, but you can also just call the action you want to perform directly and provide the appropriate connection options yourself.
You'll notice in the docs for each action that there is a first parameter, connectionOptions
, which isn't required when using the clients since they provide this for you based on the information used during instantiation. When using the action functions directly however, you need to provide the options yourself. Here is how these parameters were created for use in the examples of clientless usage below:
import { DEFAULT_API_URL, COMMON_HEADERS } from 'hypothesis-rest'
// ...
export const apiKeyHeaders = {
Authorization: `Bearer ${YOUR_API_KEY}`
}
export const authClientHeaders = {
Authorization: `Bearer ${AUTH_CLIENT_TOKEN}`
}
export const authClientForwardedUserHeaders = {
'X-Forwarded-User': AUTH_CLIENT_FORWARDED_USER_TOKEN
}
export const unauthenticatedConnectionOptions = {
apiUrl: DEFAULT_API_URL,
headers: COMMON_HEADERS
}
export const apiKeyConnectionOptions = {
apiUrl: DEFAULT_API_URL,
headers: { ...COMMON_HEADERS, ...apiKeyHeaders }
}
export const authClientConnectionOptions = {
apiUrl: DEFAULT_API_URL,
headers: { ...COMMON_HEADERS, ...authClientHeaders }
}
export const authClientForwardedUserConnectionOptions = {
apiUrl: DEFAULT_API_URL,
headers: { ...COMMON_HEADERS, ...authClientForwardedUserHeaders }
}
expectType<Annotation>(
await fetchAnnotation(unauthenticatedConnectionOptions, ANNOTATION_ID)
)
expectType<Annotation>(
await createAnnotation(apiKeyConnectionOptions, NEW_ANNOTATION)
)
expectType<Group>(
await fetchGroup(authClientConnectionOptions, GROUP_ID)
)
From ./examples/clientless/authClientForwardedUser.test-d.ts#20~24
expectType<IndexResponse>(
await root(authClientForwardedUserConnectionOptions)
)
Generated using TypeDoc