CURL is a utility function that has been available as a Developer Preview feature in Couchbase Eventing Functions. It has been in developer preview and was not recommended for production. We are listening to feedback to improve usability, and we have several new enhancements coming up:

  1. Automatic parsing of common types of data

  2. Automatic marshaling of common types of data

  3. Ability to access HTTP request and response headers

  4. Ability to handle HTTPS connections

  5. Support for session cookies

  6. Additional authentication types supported

There are some changes to CURL coming in Couchbase Server 6.5. This blog post will give you a small preview of what’s coming in 6.5. It also serves as a reference point for some older blog posts that were using the old CURL API.

If you are interested in trying an early build of Couchbase Server 6.5 before the beta release in summer 2019, please contact matthew.groves@couchbase.com.

Eventing 6.5 Specification

There are improvements and enhancements coming to Eventing in Couchbase Server 6.5. You can read the entire Eventing 6.5 Specification on GitHub. For this post, I want to highlight CURL, which has changed considerably from its first developer preview.

URL alias Bindings for CURL

To use CURL in an event, you must create a URL alias in the Function Settings. Specify the base URL that you will be making a call to with CURL. For instance, I want to make calls to the Open Weather Map API. The base URL for the API is https://samples.openweathermap.org. In Function Settings, I added a binding:

  • URL alias (binding type)

  • weatherUrl (binding name)

  • https://samples.openweathermap.org (binding value)

Function settings

I also added a bucket alias binding to the demo bucket, which is also the source bucket. This allows me to read and write from the demo bucket.

Function code

I created a very simple Eventing function that will run whenever a document is changed, then retrieve the weather from OpenWeatherMap and finally save the weather data to the document.

Notice that the curl method in this code takes three arguments:

  • The HTTP method (GET in this example)

  • The URL alias binding (weatherUrl)

  • A request object (request). In this example, it’s very simple with only a path and a params value, but you can also add headers, body, and encoding. Make sure to check out the entire specification.

Next steps

If you’ve been using curl in developer preview, it’s important that you update to use this new and improved curl. If you’re interested in trying an early build of Couchbase Server 6.5 which contains the new curl function before the beta release in summer, please contact matthew.groves@couchbase.com.

Posted by Matthew Groves, Developer Advocate

Matthew is a Developer Advocate for Couchbase, and lives in the Central Ohio area. He has experience as a web developer as a consultant, in-house developer, and product developer. He has been a regular speaker at conferences and user groups all over the United States, and he has written AOP in .NET for Manning Books. He has experience in C# and .NET, but also with other web-related tools and technologies like JavaScript and PHP. You can find him on Twitter at @mgroves.

Leave a reply