The library that calls your APIs for you
Rivet parses third party API documentation and automatically transforms requests and responses to the shapes of your choosing, so you can leverage data structures that your application already uses. Any external API you use in your application will "just work."
npm install @rivet-one/rivet
Or the equivalent in your package manager.
You must use the @rivet-one
-scoped package. Omitting the scope will install something else.
There are two steps to using Rivet to make an API call: configuring the Proc
in the Rivet dashboard; and calling the Proc
from your code.
- Configuring a
Proc
in the Rivet dashboard- Visit the Rivet dashboard, log in, and select a
Project
or create a newProject
.-
Project
s are one-to-one with your apps. For each application you build which uses Rivet, you will create oneProject
. - Note the
API Key
in theProject
view; you will need this later
-
- Select a
Proc
or create a newProc
.-
Proc
s are one-to-one with external API calls. For each request you send to a third-party API, you will create oneProc
. - Note the
Proc ID
in theProc
view; you will need this later
-
- Follow the prompts, which will guide you to select a library, provide authentication secrets, define a request and response shape, and a text prompt.
- Visit the Rivet dashboard, log in, and select a
- Calling a
Proc
from your code- Set the environment variable
RIVET_API_KEY
to the API Key found in yourProject
. - Import
rivet
and callrivet.rpc
with an options object and a data object.- If using TypeScript,
rivet.rpc
can optionally be parameterized with a request type and response type.
- If using TypeScript,
- Set the environment variable
A full example in TypeScript and NodeJS might look like this:
import rivet from "rivet";
...
type Req = { foo: string };
type Rsp = { bar: string };
const rsp = await rivet.rpc<Req, Rsp>({procId: "proc1234"}, {foo: "abc"});
console.log(rsp.response?.bar);