Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.
Daniel Krook edited this page Mar 16, 2017 · 19 revisions

OpenWhisk Hands On: Creating Serverless REST APIs

This wiki contains the getting started content posted to both Bluemix and the Accelerate developer advocacy site.

Bluemix tile title and description

Build serverless REST API handlers Create actions that execute logic to execute in response to HTTP REST API calls.

Accelerate intro

Serverless platforms like Apache OpenWhisk provide a runtime that scales automatically in response to demand, resulting in a better match between the cost of cloud resources consumed and business value gained. One of the key use cases for OpenWhisk is to map HTTP REST API calls to business logic functions that create, read, update, and delete entities. Instead of pre-provisioning resources in anticipation of demand, OpenWhisk actions are started and destroyed only as needed in response to demand. Each API method handler action scales (and is billed) independently in direct correlation to the volume of requests

Accelerate overview

This project shows the power of serverless, event-driven architectures to execute code that scales automatically in response to demand from HTTP REST API calls. No resources are consumed until the API endpoints are called. When they are called, resources are provisioned to exactly match the current load.

It shows four OpenWhisk actions (written in JavaScript) that write and read data in a MySQL database. This demonstrates how actions can work with supporting data services and execute logic in response to HTTP requests.

One action is mapped to HTTP POST requests. It inserts the supplied cat name and color parameters into the database. A second action is mapped to PUT requests to update those fields for an existing cat. A third action is mapped to GET requests that return specific cat data. A fourth action deletes a given cat data.

The Node.js runtime on Bluemix provides a built-in whitelist of NPM modules. This demo also highlights how additional Node.js dependencies - such as the MySQL client - can be packaged in a ZIP file with custom actions to provide a high level of extensibility.

Accelerate flow and diagram

  1. The API client sends an HTTP POST request to the REST API.
  2. The API gateway receives the request and forwards it to an OpenWhisk action
  3. The OpenWhisk action extracts the request body parameters, and uses the NPM MySQL client to create an SQL INSERT.
  4. The cat data is stored in the database.
  5. This flow repeats for the GET, PUT, and DELETE requests to read, update, and delete cat data.

Accelerate components

  • OpenWhisk
  • MySQL from Compose

Accelerate technology

  • OpenWhisk
  • MySQL from Compose

Accelerate links

  • What makes serverless architectures so attractive? - Serverless architectures are one of the hottest trends in cloud computing this year, and for good reason. There are several technical capabilities and business factors coming together to make this approach very compelling from both an application development and deployment cost perspective.

  • Build a cloud native app with Apache OpenWhisk - At this live coding event, Daniel Krook provides an overview of serverless architectures, introduces the OpenWhisk programming model, and then deploys an OpenWhisk application on IBM Bluemix, while you watch, step-by-step.

Accelerate blog post

Autoscale your REST APIs with OpenWhisk

Imagine that your team is a mobile video game studio of three people. You just released an addictive new puzzle game that users can play with friends. People love it. Then Apple features it on the App Store. The social connections overload your backend services. Score data overwhelms your database. The one-star reviews pour in.

But it doesn't have to be this way. If you had implemented your backend logic as individual microservices deployed to a serverless platform like OpenWhisk, the system could have autoscaled to match demand exactly. And you would have paid only for the resources consumed in direct proportion to the number of users that paid for your game.

This is the promise of an event-driven, serverless architecture for new cloud-native applications such as those that support the microservices needed for mobile gaming backends. Check out the new OpenWhisk demo on building Serverless HTTP REST APIs and start dreaming about building your next hit game, not worrying about its backend infrastructure.