카우치베이스 서버

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

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 에서 자세한 내용을 확인하세요.

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

 

 

 

 

 

이 문서 공유하기
받은 편지함에서 카우치베이스 블로그 업데이트 받기
이 필드는 필수 입력 사항입니다.

작성자

게시자 로랑 도귄

Laurent는 파리에 사는 괴짜 금속공학도입니다. 주로 Java로 코드를 작성하고 AsciiDoc으로 구조화된 텍스트를 작성하며 데이터, 리액티브 프로그래밍 및 기타 유행어에 대해 자주 이야기합니다. 또한 Clever Cloud와 Nuxeo의 개발자 옹호자로 활동하며 해당 커뮤니티가 더 크고 강력하게 성장할 수 있도록 자신의 시간과 전문성을 바쳤습니다. 현재 Couchbase에서 개발자 관계를 운영하고 있습니다.

댓글 남기기

카우치베이스 카펠라를 시작할 준비가 되셨나요?

구축 시작

개발자 포털에서 NoSQL을 살펴보고, 리소스를 찾아보고, 튜토리얼을 시작하세요.

카펠라 무료 사용

클릭 몇 번으로 Couchbase를 직접 체험해 보세요. Capella DBaaS는 가장 쉽고 빠르게 시작할 수 있는 방법입니다.

연락하기

카우치베이스 제품에 대해 자세히 알고 싶으신가요? 저희가 도와드리겠습니다.