Skip to content

Instantly share code, notes, and snippets.

@vkarpov15 vkarpov15/ Secret
Last active Mar 10, 2018

What would you like to do?
"Hello, World" in LunchBadger vs Apigee Edge

Apigee Edge is a popular platform for deploying API proxies that was acquired by Google in 2016. LunchBadger, like Apigee, allows you to build and deploy API gateways on their internal cloud computing service. At a high level, LunchBadger and Apigee are similar, but there are several key differences in terms of Node.js version compatibility and vendor lock-in that you should be aware of before choosing one or the other.

Deploying a Node.js Application to Apigee Edge

Before you deploy a Node.js app to Apigee, you need to be aware that Apigee currently only supports Node.js v0.10.32. There is no way to use another version. Node.js 0.10.32 was released in 2014 and has been formally deprecated since 2016, so many modern Node.js libraries will not work on Apigee.

To create a new API Gateway with Apigee, log into the Apigee Edge console and click on "API Proxies."

Click on the add proxy button on the upper right corner to create a new proxy.

For a fair comparison with LunchBadger, click "Node.js App" to create a new Node application, and upload the below hello-apigee.js file. Note that with Apigee, your Node.js app needs to expose an HTTP server, Apigee does not currently support any sort of function-as-a-service interface.

var http = require('http');

var svr = http.createServer(function(req, resp) {
  resp.writeHead(200, { 'Content-Type': 'text/plain' });
  resp.end('Hello, World! ' + process.version + '\n');

svr.listen(9000, function() {
  console.log('The server is listening on port 9000');

In the "Security" step, select "Pass through" so make it easy to access your API Gateway. In production you would likely set API Key security here, but for this simple example you shouldn't set up any security.

For the "Virtual Hosts" and "Build" steps, just hit next and skip those steps. When you get to the "Summary" step, Apigee will deploy your API Gateway for you.

Once your API Gateway is finished deploying, you should be able to access your endpoint using curl. Note once again that the Node.js version is v0.10.32.

$ curl
Hello, World! v0.10.32

You may see the following error when accessing your endpoint using curl. This error usually occurs because it takes a little time for Apigee to finish deploying your API Gateway after the web interface says it is done. If you see this error, wait a couple minutes and try again.

$ curl
{"fault":{"faultstring":"APIProxy revision 1 of test does not exist in environment test of organization val-eval","detail":{"errorcode":"messaging.runtime.ApplicationNotFound"}}}

For more sophisticated Node.js applications you need to use Apigee's apigeetool library to bundle your application. Unfortunately, apigeetool is known for giving mysterious HTTP 401 errors with no further information, so working with apigeetool requires more sophistication.

LunchBadger and Express Gateway

In LunchBadger, first create a new function and name it 'myfunction':

Node.js functions in LunchBadger have the same function signature as native Node.js HTTP request listeners. The function to print 'Hello, world!' with LunchBadger is shown below. Note that the exported function must have the same name as the function name you assigned in the LunchBadger GUI.

module.exports = {
  myfunction (req, res) {
    res.end('Hello, world!');

Note that this function does not have to create an actual HTTP server. LunchBadger handles creating a server for you, so you can write "serverless" functions without having to actually write an express application. You do still get access to the Node.js HTTP response, so you can set HTTP headers and set the HTTP status code.

From the menu on the left, add a new gateway. This will add an Express Gateway instance to your project.

Click the plus icon next to "Policies" to add a policy to the default Express Gateway pipeline. In Express Gateway, a pipeline is a sequence of policies for handling a request. Add an empty 'proxy' pipeline.

Drag a line from your gateway to your function, and LunchBadger will automatically connect your proxy policy to your function.

LunchBadger will also create a function endpoint for you. Keep the "paths" for your function endpoint empty for now. Click on the "settings" icon to find the publicly accessible URL for your LunchBadger project.

Running curl on the URL will now run your custom function and give you the "Hello, world!" text.

$ curl
Hello, World!

Moving On

The combination of LunchBadger and Express Gateway is a great alternative to Apigee for Node.js developers if you're looking to leverage modern JavaScript. In particular, Apigee requires you to use a version of Node.js that's been deprecated for several years at the time of this writing. LunchBadger also allows you to simply write functions, rather than requiring you to build out a whole server application and then deploy it using an error-prone command line tool. Apigee is appealing if you want to deploy an existing Node.js application somewhere, or if you don't want to use Node.js and just use their web GUI to configure your API Gateway. However, the latter approach suffers from vendor lock-in, because you can't simply take your API Gateway from Apigee's GUI and run it locally or on a different cloud provider. LunchBadger's GUI generates a git project for you, so you can clone your entire API Gateway stack, modify it in your preferred code editor, and run it locally or on your cloud provider of choice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.