Servidor Couchbase

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 Ejemplo

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 nube.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 para más información.

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

 

 

 

 

 

Comparte este artículo
Recibe actualizaciones del blog de Couchbase en tu bandeja de entrada
Este campo es obligatorio.

Autor

Publicado por Laurent Doguin

Laurent es un metalero empollón que vive en París. Principalmente escribe código en Java y texto estructurado en AsciiDoc, y a menudo habla sobre datos, programación reactiva y otras cosas de moda. También fue Developer Advocate de Clever Cloud y Nuxeo, donde dedicó su tiempo y experiencia a ayudar a esas comunidades a crecer y fortalecerse. Ahora dirige las relaciones con los desarrolladores en Couchbase.

Deja un comentario

¿Listo para empezar con Couchbase Capella?

Empezar a construir

Consulte nuestro portal para desarrolladores para explorar NoSQL, buscar recursos y empezar con tutoriales.

Utilizar Capella gratis

Ponte manos a la obra con Couchbase en unos pocos clics. Capella DBaaS es la forma más fácil y rápida de empezar.

Póngase en contacto

¿Quieres saber más sobre las ofertas de Couchbase? Permítanos ayudarle.