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.

Author

Posted by Matthew Groves

Matthew D. Groves is a guy who loves to code. It doesn't matter if it's C#, jQuery, or PHP: he'll submit pull requests for anything. He has been coding professionally ever since he wrote a QuickBASIC point-of-sale app for his parent's pizza shop back in the 90s. He currently works as a Senior Product Marketing Manager for Couchbase. His free time is spent with his family, watching the Reds, and getting involved in the developer community. He is the author of AOP in .NET, Pro Microservices in .NET, a Pluralsight author, and a Microsoft MVP.

Leave a reply