1. Install

npm i hypothesis-rest

2. Import

import HypothesisRestClient from 'hypothesis-rest'

3. Authentication

Get a client appropriate to your authorization requirements, it will provide you with only those API endpoints available with this authentication method:

"Unauthenticated" Client:

From ./examples/clients/unauthenticated.test-d.ts#20~23

  const client = HypothesisRestClient()
expectType<UnauthenticatedClient>(client)

"API key" Client:

From ./examples/clients/apiKey.test-d.ts#26~29

  const client = HypothesisRestClient({ apiKey: '<YOUR_API_KEY>' })
expectType<ApiKeyClient>(client)

"Auth Client" Client:

From ./examples/clients/authClient.test-d.ts#17~20

  const client = HypothesisRestClient({ authClient: '<OAUTH2_TOKEN>' })
expectType<AuthClientClient>(client)

"Auth Client Forwarded User" Client:

From ./examples/clients/authClientForwardedUser.test-d.ts#16~19

  const client = HypothesisRestClient({ authClientForwardedUser: '<FORWARDED_USER_OAUTH2_TOKEN>' })
expectType<AuthClientForwardedUserClient>(client)

See which endpoints support or require which auth types in the endpoints table below, or go directly to the Hypothesis docs on Authorization

4. Perform requests

e.g. Fetch an Annotation unauthenticated

From ./examples/clients/unauthenticated.test-d.ts#45~49

    expectType<Annotation>(
await client.annotations.fetchAnnotation(ANNOTATION_ID)
)

e.g. Create an Annotation using an API key

From ./examples/clients/apiKey.test-d.ts#51~55

    expectType<Annotation>(
await client.annotations.createAnnotation(NEW_ANNOTATION)
)

e.g. Fetch a Group using an Auth Client

From ./examples/clients/authClient.test-d.ts#41~45

    expectType<Group>(
await client.groups.fetchGroup(GROUP_ID)
)

e.g. Fetch the API root using an Auth Client Forwarded User

From ./examples/clients/authClientForwardedUser.test-d.ts#25~29

    expectType<IndexResponse>(
await client.root()
)

Clientless usage

Error Handling

Generated using TypeDoc