Couchbase Server

Couchbase’s Data API in Practice With NodeRed

Couchbase Capella has a new Data API. If you’re wondering why it is important since we already have SDKs, the answer is addressed in our documentation – but here’s a quick comparison:

  • Data API: HTTP, language, and runtime agnostic; easy integration with zero dependency; plus trade-offs in latency, throughput, and resiliency features.
  • SDKs: Native library, richer features, better performance, better suited to workloads where scale and resilience matter.

Some use cases:

  • Functions for FaaS/Serverless: AWS Lambda, Google Cloud Functions, Azure Functions, Netlify Functions
  • SaaS integrations: Zapier, IFTTT, Relay, Make, N8N, Flowwise, Node-RED
  • Scripting: Jenkins Pipeline or GitHub Actions
  • Internal tools: Dashboard, Grafana

All of these use cases can be implemented but would require either the deployment and management of your own Couchbase SDK-backed API, or ensuring SDKs were available where the code was running – which in some cases is impossible.

With that, let’s see how this all works in practice with a use case example.

Node-RED Example

Node-RED enables low-code programming for event-driven applications. It’s visual, simple, lightweight, and it runs on a wide range of hardware platforms. However, while it supports the use of external modules, some – especially those that depend on native libraries, such as our Node SDK, can  be difficult to use. This presents a perfect excuse to try the new Data API.

Below is a simple use case that tries to scrape data from luma to know what’s going on in Paris. You can see the results below. Note, the top-level flow is the ingestion, the second is the debugging query. 

Ingestion Flow

  • Start: An ingest node that triggers this every 72 hours.
  • Query luma: An HTTP request to https://luma.com/paris.
  • Extract events: An HTML parser to retrieve the list of events as String.
  • Convert to JSON: A JSON parser to turn this String in a JSON Object.
  • Parse_to_events: A function that takes this object and creates a new one with only the required data.

The code looks like this:

  • forEach: A Split tasks that splits the events JSON object from the previous step.
  • Create event in Couchbase: An HTTP request is sent to the Capella Data API. Whatever is in the payload of the previous step will be the body of the request. You can use Mustache templating for the URL field. Here’s a screenshot of the actual step; it’s like running this curl command:

  • Debug1: A debug step to see the results of all the requests. 

Debug FLow

  • Start: An ingest node that must be triggered manually.
  • SQL_Query: A function that returns a JSON object representing the query to run.

  • Query events in Couchbase: An HTTP Request that runs the given query. It would look like the following curl command:

Try It Yourself

Node-RED can easily be run on your machine with docker run -it -p 1880:1880 --name mynodered nodered/node-red

Then go to http://127.0.0.1:1880/ and follow the instructions. You can either create the nodes by hand or import this flow with this JSON export:

You will need a Capella instance with the Data API enabled. It’s available in our Free Tier and is easy to test. Just go to cloud.couchbase.com, open your cluster, and go to the connect tab. You will then click on Enable Data API. This can take up to 20 minutes to be ready, so in the interim you can follow the instructions about IP addresses and credentials. 

You now have everything you need to use the Data API, specifically the URL endpoint of the API. You can also access the Reference Documentation for more information.

We hope you enjoy this new Capella feature, and all the use cases that are now available to you.

 

 

 

 

 

Share this article
Get Couchbase blog updates in your inbox
This field is required.

Author

Posted by Laurent Doguin

Laurent is a nerdy metal head who lives in Paris. He mostly writes code in Java and structured text in AsciiDoc, and often talks about data, reactive programming and other buzzwordy stuff. He is also a former Developer Advocate for Clever Cloud and Nuxeo where he devoted his time and expertise to helping those communities grow bigger and stronger. He now runs Developer Relations at Couchbase.

Leave a comment

Ready to get Started with Couchbase Capella?

Start building

Check out our developer portal to explore NoSQL, browse resources, and get started with tutorials.

Use Capella free

Get hands-on with Couchbase in just a few clicks. Capella DBaaS is the easiest and fastest way to get started.

Get in touch

Want to learn more about Couchbase offerings? Let us help.