@rivet-one/rivet
v0.0.4
Published
The library that calls your APIs for you
Downloads
34
Readme
Rivet
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."
Installation
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.
Use
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
Procin the Rivet dashboard- Visit the Rivet dashboard, log in, and select a
Projector create a newProject.Projects are one-to-one with your apps. For each application you build which uses Rivet, you will create oneProject.- Note the
API Keyin theProjectview; you will need this later
- Select a
Procor create a newProc.Procs 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 IDin theProcview; 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
Procfrom your code- Set the environment variable
RIVET_API_KEYto the API Key found in yourProject. - Import
rivetand callrivet.rpcwith an options object and a data object.- If using TypeScript,
rivet.rpccan 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);