DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Because the DevOps movement has redefined engineering responsibilities, SREs now have to become stewards of observability strategy.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Related

  • How To Set Up a Scalable and Highly-Available GraphQL API in Minutes
  • Build a Simple REST API Using Python Flask and SQLite (With Tests)
  • Build a REST API With Just 2 Classes in Java and Quarkus
  • Micronaut vs Spring Boot: A Detailed Comparison

Trending

  • IoT and Cybersecurity: Addressing Data Privacy and Security Challenges
  • Exploring Intercooler.js: Simplify AJAX With HTML Attributes
  • Building a Real-Time Change Data Capture Pipeline With Debezium, Kafka, and PostgreSQL
  • Web Crawling for RAG With Crawl4AI
  1. DZone
  2. Data Engineering
  3. Databases
  4. Getting Started With the YugabyteDB Managed REST API

Getting Started With the YugabyteDB Managed REST API

In this article, learn how to generate an API key, list existing clusters, create a new cluster, and stream market orders into the cluster.

By 
Denis Magda user avatar
Denis Magda
DZone Core CORE ·
May. 29, 23 · Tutorial
Likes (1)
Comment
Save
Tweet
Share
10.8K Views

Join the DZone community and get the full member experience.

Join For Free

REST API is so widespread that you can even use it to manage distributed SQL databases. In this blog post, I will show you how to manage and work with YugabyteDB Managed clusters via REST. You'll learn how to generate an API key, retrieve a list of existing clusters, create a new cluster, and finally, start a sample application that streams market orders into the cluster. Let's get started!

Generating a YugabyteDB Managed API Key

First, you'll need an API key to interact with the YugabyteDB Managed REST API. 

To generate a new key, follow these steps:

YugabyteDB Admin: Access Control

Follow along with the sister video—YugabyteDB Managed REST API

  1. Head over to the YugabyteDB Managed UI.
  2. Navigate to the API Keys section.
  3. Click on the Create API Key button.
  4. Give the key a name, select a role (e.g., 'Developer' or 'Admin'), and define an expiration time.
  5. Click on the Generate API Key button.

Once the key is generated, copy it somewhere safe, since you will not be able to see it again.

You need to use this API key in the Authorization:Bearer header for all your requests to YugabyteDB Managed. If you use httpie, then your first REST request can be as simple as this:

Shell
 
http GET https://cloud.yugabyte.com/api/public/v1/accounts \
	-A bearer -a {YOUR_API_KEY}


Retrieve a List of Existing YugabyteDB Clusters

Next, let’s run more sophisticated requests via REST. How about getting a list of YugabyteDB Managed clusters?

To fetch that list, you need to make an API call to the clusters endpoint:

Shell
 
http GET https://cloud.yugabyte.com/api/public/v1/accounts/{YOUR_ACCOUNT_ID}/projects/{YOUR_PROJECT_ID}/clusters \
	-A bearer -a {YOUR_API_KEY}


For this and many other API endpoints, you'll need to provide the accountID and the projectID. You can find these values in the URL of your YugabyteDB Managed UI.

YugabyteDB Admin: API Keys

After making this API call to the clusters endpoint, you'll get a JSON response containing the list of database clusters. If the data field is empty, it means there are no database clusters yet.

JSON
 
{
  "_metadata": {
    "continuation_token": null,
    "links": {
      "next": null,
      "self": "/api/public/v1/accounts/{YOUR_ACCOUNT_ID}/projects/{YOUR_PROJECT_ID}/clusters"
    }
  },
  "data": []
}


Create a YugabyteDB Managed Cluster

To create a new YugabyteDB Managed cluster, you'll need to make a POST HTTP request to the clusters endpoint and provide the necessary cluster configuration details.

Here's an example request for provisioning a new distributed YugabyteDB cluster:

Shell
 
http POST https://cloud.yugabyte.com/api/public/v1/accounts/{YOUR_ACCOUNT_ID}/projects/{YOUR_PROJECT_ID}/clusters \
	-A bearer -a {YOUR_API_KEY} < cluster_config.json


The clusters_config.json file includes a required cluster configuration in JSON format. The configuration below requests to start a 3-node cluster in the us-east1 region of the Google Cloud Platform:

JSON
 
{
"cluster_spec": {
  "name": "sample-cluster",
  "cluster_info": {
    "cluster_tier": "PAID",
    "cluster_type": "SYNCHRONOUS",
    "num_nodes": 3,
    "fault_tolerance": "ZONE",
    "node_info": {
      "num_cores": 2,
      "memory_mb": 8192,
      "disk_size_gb": 50
    },
    "is_production": false,
    "version": null
  },
"software_info": {
  "track_id": "d9618d5e-9591-445b-a280-705770f5fb30"
    },
"cluster_region_info": [
  {
    "placement_info": {
      "cloud_info": {
        "code": "GCP",
        "region": "us-east1"
      },
      "num_nodes": 3,
      "multi_zone": true
    },
    "is_default": true,
    "is_affinitized": true,
    "accessibility_types": [
      "PUBLIC"
    ]
  }
]
},
"db_credentials": {
  "ycql": {
    "username": "admin",
    "password": "SuperStrongPassword"
  },
  "ysql": {
    "username": "admin",
    "password": "SuperStrongPassword"
  }
}
}


Once you've sent this POST request, your new cluster will start to provision.

JSON
 
"cluster_endpoints": [{
    "accessibility_type": "PUBLIC",
    "host": null,
    "id": "5e24c4d3-3329-47e1-ba95-5f1fa36a86f0",
    "pse_id": null,
    "region": "us-east1",
    "state": "CREATING",
    "state_v1": "CREATING"
 }]


You can continue checking the cluster status using the REST API, or you can wait while the deployment is finished with the YugabyteDB Managed UI.

YugabyteDB Managed UI: sample-cluster

Start a Sample Application and Monitoring Cluster Metrics

Now that you have your YugabyteDB Managed cluster up and running, let's start a sample application that streams market orders into the cluster.

Once you start the application, make sure it is connected to the cluster, and streams market orders into the database as expected:

Java
 
============= Trade Stats ============

Trades Count: 1040

Stock           Total Proceeds  
Linen Cloth     2815.790039     
Google          2201.330078     
Bespin Gas      2132.620117     
Apple           1536.520020     
Elerium         1189.439941     
======================================


Next, let's use YugabyteDB Managed REST API to confirm the incoming requests using the cluster-metrics API endpoint:

Shell
 
http GET https://cloud.yugabyte.com/api/public/v1/accounts/{YOUR_ACCOUNT_ID}/projects/{YOUR_PROJECT_ID}/cluster-metrics?cluster_ids={YOUR_CLUSTER_ID} \
	-A bearer -a {YOUR_API_KEY}


  • cluster_ids parameter: You can find your cluster’s ID by sending the GET request to the clusters API endpoint (see the retrieving the clusters list section above) or by locating through the YugabyteDB Managed UI.

If everything is working as expected, you'll see your cluster's metrics data, including the number of active read and write requests.

JSON
 
{
  "data": [
    {
      "cluster_id": "bf7e8c4e-3540-4afb-a382-1b87d31cc0d8",
      "metrics": {
        "read_ops_per_second": 5.0,
        "write_ops_per_second": 10.0
      }
    }
  ]
}


Congratulations!

Congratulations! You now know how to use the YugabyteDB Managed REST API to generate an API key, retrieve a list of existing clusters, create a new cluster, and monitor the cluster metrics while streaming market orders from a sample application. 

You can now take full advantage of YugabyteDB Managed and its REST API to manage your database clusters more efficiently and programmatically.

API REST YugabyteDB cluster

Opinions expressed by DZone contributors are their own.

Related

  • How To Set Up a Scalable and Highly-Available GraphQL API in Minutes
  • Build a Simple REST API Using Python Flask and SQLite (With Tests)
  • Build a REST API With Just 2 Classes in Java and Quarkus
  • Micronaut vs Spring Boot: A Detailed Comparison

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!