Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

The Data Theorem API Protect NodeJS SDK is a NodeJS library that provides protection for APIs written in Javascript. The SDK integrates with your NodeJS API using the API Protect middleware which supports most popular NodeJS frameworks, including:

To Protect an API, all the API developer needs to do is add the API Protect middleware to their web application code set the client Id we provide

...

Code Block
const express = require('express');
const apiprotect = require('apiprotect');

const app = express();

// Register body parsing middlware then APIProtect middlware
app.use(express.json());
app.use(apiprotect.default()); // ClientId read from ENV: `DT_API_PROTECT_CLIENT_ID`

...

For each API you protect Data Theorem provides a unique identifier which authenticates the SDK when it communicates with our services. The client id we provide can be set in two way, either via an environment variable DT_API_PROTECT_CLIENT_ID or by passing it directly to the middleware.

The client id is in a file named client_id in the sdk bundle you downloaded.

Example setting the client id via ENV Var

> source ./client_id && npm run

Setting the environment variable is the preferred way, but if you need to pass it to the middleware, here is how to do that:

Example passing

...

clientId to Express middleware

Code Block
languagejs
const express = require('express');
const apiprotect = require('apiprotect');
const settings = require('settings')l

const app = express();

// Register body parsing middlware then APIProtect middlware
app.use(express.json());
app.use(apiprotect.default(settings.clientId)); // ClientId passed as param

...