How to use the TypeScript SDK
Prerequisites
- An API key
- Familiarity with command-line tools
- Basic familiarity with TypeScript and Node.js; Node 18+ installed
Installation
Our TypeScript SDK is hosted at NPM.
Use npm
or yarn
to install it to your project:
Instantiate a client
Import FluidStackApiClient
and instantiate a TypeScript client with your API key:
Now you can use the client to consume the API from your TypeScript application.
Warning
Avoid placing your API key in any file that might be shared with others. For information on using a .env
file instead of adding the API key directly into a file, see: API Overview - Secure use of your API key.
Use the FluidStack TypeScript client in your app
The FluidStack TypeScript client simplifies making API requests. It stores the API key that you used to instantiate it, and it already knows our API server’s base URL, so you can omit those details in your requests.
The SDK also provides code hints, type hints, parameter information, and other useful functions to speed up development.
For example, compare the tabs below:
You can see that instead of using fetch
or a similar module to send an HTTP request and including the endpoint path and headers each time, the FluidStack TypeScript client simplifies the request for you.
Call endpoints
Requests to API endpoints are implemented in the SDK as methods of the client. For example, the GET /instances endpoint is implemented like this:
In TypeScript/JavaScript, you must handle asynchronous operations such as HTTP requests explicitly using async/await
or promises. To use async/await
, wrap the method call in an async
function and await
the result, then call the function:
The code shown above does not do anything with the response from the endpoint. It is up to you to handle the response, including error handling.
For example, you could simply print the entire response to the terminal:
Or you could loop through the list and print only the name and status for each instance:
See Programmatic Instance Management for a more detailed tutorial on using TypeScript, Python, and their respective SDKs.
Instances
List user instances
Create an instance
Fetch an instance
Stop an instance
Start an instance
Terminate an instance
Parameters: None.
SSH Keys
List SSH keys
Add an SSH key
Delete an SSH key
Parameters: None.
List available configurations and operating system templates
Configurations
OS Templates
Parameters: None.