All Projects → IBM → ibm-cloud-functions-rest-api-trigger

IBM / ibm-cloud-functions-rest-api-trigger

Licence: Apache-2.0 license
IBM Cloud Functions building block - HTTP REST Trigger - This project provides a starting point for handling events from REST API calls with IBM Cloud Functions powered by Apache OpenWhisk.

Projects that are alternatives of or similar to ibm-cloud-functions-rest-api-trigger

ibm-cloud-functions-serverless-ocr-openchecks
Serverless bank check deposit processing with object storage and optical character recognition using Apache OpenWhisk powered by IBM Cloud Functions. See the Tech Talk replay for a demo.
Stars: ✭ 40 (+135.29%)
Mutual labels:  bluemix, openwhisk, ibm-developer-technology-cloud, openwhisk-getting-started, ibm-cloud-functions
ibm-cloud-functions-action-trigger-rule
Simple demo showing Apache OpenWhisk actions, triggers, and rules with IBM Cloud Functions.
Stars: ✭ 16 (-5.88%)
Mutual labels:  openwhisk, openwhisk-getting-started, openwhisk-building-block, ibm-cloud-functions
multiple-deployment-options
Shows how one service can be deployed to multiple deployment options
Stars: ✭ 20 (+17.65%)
Mutual labels:  bluemix, openwhisk
slack-chatbot-database-watson
Code for the solution tutorial "Build a database-driven Slackbot" (chatbot) with a custom extension in IBM Watson Assistant
Stars: ✭ 23 (+35.29%)
Mutual labels:  openwhisk, ibm-cloud-functions
detect-timeseriesdata-change
WARNING: This repository is no longer maintained ⚠️ This repository will not be updated. The repository will be kept available in read-only mode.
Stars: ✭ 21 (+23.53%)
Mutual labels:  bluemix, ibm-developer-technology-cloud
logistics-wizard
The Logistics Wizard is an end-to-end, smart supply chain management solution that showcases how to execute hybrid cloud, microservices, and predictive data analytics in the real world.
Stars: ✭ 99 (+482.35%)
Mutual labels:  bluemix, openwhisk
banking-digitalization-using-hybrid-cloud-with-mainframes
The following journey will introduce the available Banking APIs published on IBM Cloud with logical business programs running on the IBM Z Mainframe through a simulated retail bank called MPLbank.
Stars: ✭ 21 (+23.53%)
Mutual labels:  bluemix, ibm-developer-technology-cloud
text-bot-openwhisk
DEPRECATED: this repo is no longer actively maintained
Stars: ✭ 12 (-29.41%)
Mutual labels:  bluemix, openwhisk
node-red-dsx-workflow
This journey helps to build a complete end-to-end analytics solution using IBM Watson Studio. This repository contains instructions to create a custom web interface to trigger the execution of Python code in Jupyter Notebook and visualise the response from Jupyter Notebook on IBM Watson Studio.
Stars: ✭ 26 (+52.94%)
Mutual labels:  bluemix, ibm-developer-technology-cloud
awesome-ibmcloud
A curated list of awesome IBM Cloud SDKs, open source repositories, tools, blogs and other resources.
Stars: ✭ 77 (+352.94%)
Mutual labels:  bluemix
openwhisk-deploy-openshift
[DEPRECATED] - This project can be used to deploy Apache OpenWhisk to the OpenShift platform
Stars: ✭ 22 (+29.41%)
Mutual labels:  openwhisk
openwhisk-client-swift
[DEPRECATED] - openwhisk-client-swift is a Swift client SDK for OpenWhisk with support for iOS, WatchOS2, and Darwin CLI apps
Stars: ✭ 20 (+17.65%)
Mutual labels:  openwhisk
voipms-sms-firebase
IBM Cloud Function used to implement push notifications for VoIP.ms
Stars: ✭ 19 (+11.76%)
Mutual labels:  ibm-cloud-functions
fiware-meteoroid
Meteoroid realizes integrating Function as a Service(FaaS) capabilities in FIWARE. It provides a management interface specialized for FaaS and FIWARE.
Stars: ✭ 13 (-23.53%)
Mutual labels:  openwhisk
watson-multimedia-analyzer
WARNING: This repository is no longer maintained ⚠️ This repository will not be updated. The repository will be kept available in read-only mode. A Node app that use Watson Visual Recognition, Speech to Text, Natural Language Understanding, and Tone Analyzer to enrich media files.
Stars: ✭ 23 (+35.29%)
Mutual labels:  bluemix
openwhisk-catalog
Curated catalog of Apache OpenWhisk packages to interface with event producers and consumers
Stars: ✭ 30 (+76.47%)
Mutual labels:  openwhisk
openwhisk-runtime-docker
Apache OpenWhisk SDK for building Docker "blackbox" runtimes
Stars: ✭ 23 (+35.29%)
Mutual labels:  openwhisk
openwhisk-vscode
[DEPRECATED] - Visual Studio Code extension (prototype) for authoring OpenWhisk actions inside the editor.
Stars: ✭ 19 (+11.76%)
Mutual labels:  openwhisk
openwhisk-runtime-java
Apache OpenWhisk Runtime Java supports Apache OpenWhisk functions written in Java and other JVM-hosted languages
Stars: ✭ 43 (+152.94%)
Mutual labels:  openwhisk
openwhisk-runtime-go
Apache OpenWhisk Runtime Go supports Apache OpenWhisk functions written in Go
Stars: ✭ 31 (+82.35%)
Mutual labels:  openwhisk

Triggering IBM Cloud Functions on HTTP REST API calls

Read this in other languages: 한국어.

Create REST API mappings with IBM Cloud Functions powered by Apache OpenWhisk. This tutorial should take about 5 minutes to complete. After this, move on to more complex serverless applications such as those tagged openwhisk-hands-on-demo.

Sample Architecture

If you're not familiar with the Cloud Functions/OpenWhisk programming model try the action, trigger, and rule sample first. You'll need an IBM Cloud account and the latest OpenWhisk (ibmcloud fn) or IBM Cloud command line plugin (ibmcloud fn).

This example provides two REST endpoints for HTTP POST and GET methods that are mapped to corresponding create-cat and fetch-cat Cloud Functions (OpenWhisk actions).

  1. Create Cloud Functions
  2. Create REST endpoints
  3. Clean up

1. Create Cloud Functions

Create an action to create a cat entity

Create a file named create-cat.js. This file will define an action written as a JavaScript function. It checks for the required parameters(name and color) and returns a unique identifier for the cat, or an error if either parameter is missing.

Note: This example is simplified, and does not connect to a backend datastore. For a more sophisticated example, check out this REST API example.

function main(params) {

  return new Promise(function(resolve, reject) {

    if (!params.name) {
      reject({
        'error': 'name parameter not set.'
      });
    } else {
      resolve({
        id: 1
      });
    }

  });

}

Create an action to return a cat entity

Create a file named fetch-cat.js. This file will define another action written as a JavaScript function. It checks for the required parameter(id) and returns Tahoma, the tabby colored cat.

Note: Again, for the purpose of this simplified demo we always return Tahoma the cat, rather than connecting to a backend datastore.

function main(params) {

  return new Promise(function(resolve, reject) {

    if (!params.id) {
      reject({
        'error': 'id parameter not set.'
      });
    } else {
      resolve({
        id: params.id,
        name: 'Tahoma',
        color: 'Tabby'
      });
    }

  });

}

Upload the actions

The next step will be to deploy Cloud Functions from the JavaScript files that we just created. We also add the --web true flag, to annotate these actions as "Web Actions". This will be necessary later when we add REST endpoints as it makes the actions HTTP-aware.

ibmcloud fn action create create-cat create-cat.js --web true
ibmcloud fn action create fetch-cat fetch-cat.js --web true

Unit test the actions

Cloud Functions (OpenWhisk actions) are stateless code snippets that can be invoked explicitly or in response to an event. For right now, we will test our actions by explicitly invoking them. Later, we will trigger our actions in response to an HTTP request. Invoke the actions using the code below and pass the parameters using the --param command line argument.

ibmcloud fn action invoke \
  --blocking \
  --param name Tahoma \
  --param color Tabby \
  create-cat

ibmcloud fn action invoke \
  --blocking \
  --param id 1 \
  fetch-cat

Note: If you see any error messages, refer to the Troubleshooting section below.

2. Create REST endpoints

Create POST and GET REST mappings for /v1/cat endpoint

Now that we have our Cloud Functions created, we will expose them through the Bluemix API Gateway. To do this we use: ibmcloud fn api create $BASE_PATH $API_PATH $API_VERB $ACTION

This feature is part of the IBM Cloud Native API Management service and currently supports very powerful API management features like security, rate limiting, and more. For now though we're just using the CLI to expose our action with a public REST endpoint.

# Exposes POST /v1/cat {"name": "Tahoma", "color": "Tabby"}
ibmcloud fn api create -n "Cats API" /v1 /cat post create-cat

# Exposes /v1/cat?id=1
ibmcloud fn api create /v1 /cat get fetch-cat

In both cases, the CLI will output the URL required to use the API. Make note of it for the next section.

Test with curl HTTP requests

Take note of the API URL that is generated from the previous command. Send an HTTP POST and GET request using curl to test the actions. Remember to send the required parameters in the body of the request for POST, or as path parameters for GET. The IBM Cloud Functions system automatically forwards these parameters to the actions we created.

# POST /v1/cat {"name": "Tahoma", "color": "Tabby"}
curl -X POST -H 'Content-Type: application/json' -d '{"name":"Tahoma","color":"Tabby"}' $THE_URL_FROM_ABOVE

# GET /v1/cat?id=1
curl $THE_URL_FROM_ABOVE?id=1

3. Clean up

Remove the API mappings and delete the actions

# Remove API base which removes all the mappings
ibmcloud fn api delete /v1

# Remove actions
ibmcloud fn action delete create-cat
ibmcloud fn action delete fetch-cat

Troubleshooting

Check for errors first in the Cloud Functions activation log. Tail the log on the command line with ibmcloud fn activation poll or drill into details visually with the Cloud Functions monitoring console.

If the error is not immediately obvious, make sure you have the latest version of the ibmcloud fn CLI installed. If it's older than a few weeks, download an update.

ibmcloud fn property get --cliversion

License

Apache 2.0

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].