In this post I'm going to show you some examples of using the TypeScript SDK, but first let me share a few important links that you will want to bookmark if you'll be doing any work with it.
The TypeScript SDK can easily be used in a "vanilla" Node.JS application. To get started, check the examples linked above or create a simple Node project and install the SDK with:
npm install oci-sdk
Now pull in some dependencies. In this example, we'll use the Object Storage and the Core modules (see the full list of services supported) so we'll need to pull in
oci-core to make calls with the necessary clients. We'll also need
oci-common and we'll pull in
util to prettify our output later on.
Next, set a few variables to sore our configuration file details and our compartmentId and tenancyName:
We'll need to create an instance of an authentication provider that we'll have to pass to the clients when we construct them. For this, we'll use a ConfigFileAuthenticationDetailsProvider from the
Now we can create an instance of the ComputeClient, passing our
Now we can construct a
listInstancesRequest and call
listInstancesRequest will just be a simple object containing keys relating to the expected parameters. The call to the client will return a
Promise, so we can get our results in the
then() method, collect our instance ID and display name, and log those values.
If we save and run this script, we'll get output similar to the following:
The object storage module follows the same patterns, so it's simple to construct an
objectStorageClient and perform operations like
If Promises aren't your thing, you can use async/await:
Another option with the TypeScript SDK is to use it directly with TypeScript scripts. This gives you the added benefit of explicitly typed objects which means your IDE will provide you with plenty of insight into the SDK. Here's an example of using a TypeScript file to grab the namespace from the object storage client. It looks mostly the same, but note the addition of the types for the provider, client, request and response objects.
In this post, we looked at the brand new TypeScript SDK for OCI. We learned how to construct authentication providers, module clients, and requests and how to send those requests to the OCI API via the client instances. If you have any questions or feedback, please leave a comment below or refer to the documentation or GitHub links above. Otherwise, get started integrating this into your Node projects today!
A while back, I blogged about using Oracle Advanced Queuing (AQ) for messaging within your applications. It's a great option for durable and reliable...
I’ve written about messaging many, many times on this blog. And for good reason, too. It’s a popular subject that developers can’t seem to get enough of...
When working in the cloud, there are often times when your servers and services are not exposed to the public internet. Private virtual cloud networks ...