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!
The Oracle Notification Service is an extraordinary service. I’ve blogged about it in the past (see the Complete Guide to the Oracle Notification Service...
When adopting cloud-native technologies and certain architectures such as the microservice pattern, observability and monitoring become a huge need and...
In this short blog series, I introduced you to Project GreenThumb, a project that I created to automate and monitor the process of growing seedlings with...