# OpenFeature and OFREP

OpenFeature gives your application a common flags API. Use the Dipswitch OpenFeature adapters for JavaScript and Node.js to read from the native SDKs. The OpenFeature Remote Evaluation Protocol, called OFREP, is also available for clients that evaluate flags by HTTP.

## Dipswitch adapters

In a Node service, install the adapter and OpenFeature's server SDK.

```sh
npm install @dipswitch/openfeature-node @openfeature/server-sdk
```

```ts
import { DipswitchProvider } from '@dipswitch/openfeature-node'
import { OpenFeature } from '@openfeature/server-sdk'

export async function startFlags(serverKey: string) {
  await OpenFeature.setProviderAndWait(new DipswitchProvider({ serverKey }))
  return OpenFeature.getClient().getBooleanValue('new-checkout', false, { targetingKey: 'user-42' })
}
```

In a browser, use the public client key and pass the user ID as `targetingKey`. Clear the context when the user signs out.

```sh
npm install @dipswitch/openfeature-web @openfeature/web-sdk
```

```ts
import { DipswitchProvider } from '@dipswitch/openfeature-web'
import { OpenFeature } from '@openfeature/web-sdk'

await OpenFeature.setProviderAndWait(
  new DipswitchProvider({ clientKey: 'ds_client_...' }),
  { targetingKey: 'user-42' },
)
export const checkout = () => OpenFeature.getClient().getBooleanValue('new-checkout', false)
```

Use a native browser SDK or send the identity signature in the OFREP header described below when the environment verifies identity.

## OFREP

Dipswitch tests `@openfeature/ofrep-provider` in Node and `@openfeature/ofrep-web-provider` in Chromium. Point them to `https://edge.dipswitch.co` and use `Authorization: Bearer` or `X-API-Key` for one credential per request. Keep server keys on the server. The Node provider evaluates one flag per request. The web provider fetches a user's flags in bulk and can follow change notifications with a public client key.

For server-side applications, follow the [Java](/docs/java/), [.NET](/docs/dotnet/) or [PHP](/docs/php/) quickstart. Each guide connects an OpenFeature provider to edge using a server key.

For a direct request with a server key, send a JSON context to the single evaluation endpoint. An environment that requires verification also accepts `X-Dipswitch-Signature` when using a client key and a named user.

```ts
export async function evaluate(serverKey: string, userId: string) {
  const response = await fetch('https://edge.dipswitch.co/ofrep/v1/evaluate/flags/new-checkout', {
    method: 'POST',
    headers: { Authorization: `Bearer ${serverKey}`, 'Content-Type': 'application/json' },
    body: JSON.stringify({ context: { targetingKey: userId } }),
  })
  if (!response.ok) return false
  const flag: { value: boolean } = await response.json()
  return flag.value
}
```

For route and response details, download the [Edge OpenAPI specification](/docs/edge.openapi.json). See [Rate limits](/docs/rate-limits/) for the per-key OFREP allowance.
