Using the JavaScript SDK
The Metorial JavaScript SDK allows you to interact with the Metorial API using TypeScript or JavaScript. The SDK is available for use in the browser, Node.js, and Deno environments.
What you will learn
How to install the Metorial JavaScript SDK
How to use the SDK in the browser, Node.js, and Deno environments
How to make requests to the Metorial API using the SDK
Before you begin
References
Install the SDK
To install the Metorial JavaScript SDK, use npm or yarn:
npm install metorial
yarn add metorial
Using the SDK
To use the SDK, import the Metorial
class and create an instance with your API key:
1import Metorial from 'metorial';23let metorial = new Metorial({4 apiKey: 'metorial_sk_...'5});
You can now use the metorial
instance to make requests to the Metorial API.
Making Requests
To make a request, use the resource methods on the metorial
instance:
1// Get a server by ID2let server = await metorial.servers.get('srv_Rm4Mnheq2bfEPhBhP7SY');34// Update a server instance5let result = await metorial.serverImplementations.update('svi_Rm4Mnheq2bfEPhBhP7SY', {6 name: "updated name",7 description: "updated description"8});
Each method returns a Promise that resolves with the response data.
Using TypeScript
The SDK is written in TypeScript and includes type definitions for all API resources. You can use TypeScript to benefit from type checking and IntelliSense support:
1import Metorial from 'metorial';23let metorial = new Metorial({4 apiKey: 'metorial_sk_...'5});67let server = await metorial.servers.get('srv_Rm4Mnheq2bfEPhBhP7SY');