Easy Web Application Development for Beginners with Node-RED (2)

Objective

In this tutorial I will create a Node-RED server application that will process a request from a client web form. The server will save the request data in a NoSQL database.

Requirements

You must have:

  • Access to a Bluemix account.

1. Create a Node-RED Starter Application

Start to create a Node-RED Starter server application. A client application sends a form request to the Node-RED server, the server processes the form data and sends a response back to the client.

Node-RED is a so-called visual workflow editor, which lets you create an application workflow by dragging and dropping visual nodes onto an editor.
Continue reading

Creating a Nodejs App with Watson AlchemyAPI and CloudantDB

WIP

Requirements:

Overview:

  1. Setup
  2. Setup Details
  3. Add Watson AlchemyAPI
  4. Add Cloudant DB

Setup

  1. Login to Bluemix, in a separate tab login to Github,
  2. In Bluemix open Catalog->Boilerplates and create a ‘Node.js Cloudant DB Web Starter’ Boilerplate, named ‘<username>-nodejs-app1’, click CREATE
  3. Go to ‘Overview’, scroll down to ‘Continuous delivery’ and click ‘Enable’
  4. In the ‘Toolchain Settings’, change the name of the Toolchain to ‘<username>-nodejs-app1’, and click Create,
  5. If the Github THINK or CODE icon displays a configuration error, from the block’s dropdown icon in the topright, click the ‘Configure’ link to correct the configuration of your Github account,
  6. Go to your Github account and make sure that the repository for the new Bluemix app is created successfully,
  7. Copy the Git URL, on localhost open a commandline terminal, change to your development directory and clone the new repository,
    cd ~/dev/src/bluemix
    git clone https://github.com/remkohdev/remkohdev-nodejs-app1.git
    cd remkohdev-nodejs-app1
  8. Open the project directory in your favorite editor,
  9. Open the ‘package.json’ file and change the ‘name’ property to ‘<username>-nodejs-app1’,
  10. From the commandline, in your project directory,
    git status
    git add .
    commit -m "change package.json name property"

Continue reading

Getting Started: Creating a Java-Liberty App with Watson on Bluemix

An extended version of this tutorial, adding a Cloudant NoSQL Database and D3js data visualization, is available here.

Requirements:

  • Bluemix account
  • Github account

Steps:

  1. Create the StarterApp
  2. Add the Toolchain or Continuous Integration (CI)
  3. REST API Primer
  4. Authentication in REST API
  5. Getting the Bluemix Configuration
  6. Add the AlchemyData News API Client
  7. Add a Web Form
  8. Implement the AlchemyData News API Request
  9. Create Authorization Header for Basic Auth

1. Create the StarterApp

Continue reading

Add Serverless Programming and Data Integration on Bluemix

Add Serverless or Event-Based Programming using OpenWhisk:

  1. Go to the OpenWhisk service at https://console.ng.bluemix.net/openwhisk
  2. Click the ‘Develop’ button, which takes you to the Openwhisk editor,
  3. Create a new Action and implement the JavaScript function,
  4. At the bottom right, click the ‘View REST Endpoint’, and in the ‘cURL Example’, click the ‘Show Full Command’ to reveal the Base64 encoded authentication token for the OpenWhisk service,
  5. You can get the username:password credentials by installing the OpenWhisk ‘wsk’ command line and run:
    wsk property get --auth
    Or to Base64 encode it, run:
    wsk property get --auth | awk '{printf("%s", $3)}' | base64
  6. The way to call the OpenWhisk endpoint is using ‘Basic Auth’:
    https://openwhisk.ng.bluemix.net/api/v1/namespaces/<organization_id>_<space>/actions/<action>?blocking=true
  7. Then, for example:

    • Next create a new action and link the two actions together by Extending the first action and link it to the second action.
    • Next create an action to save the result to the Cloudant Database using the ‘Create Document’ action,
    • Next trigger the Slack notification

Using Twitter data via DashDB:

  1. Create a DashDB service
  2. Create a Insights for Twitter service
  3. Open the DashDB dashboard > Load > Load Twitter Data > select the Twitter Service we created > Next
  4. In the Search for Twitter data: “#SEC posted:2016-11-01,2016-11-15”
  5. Click Get Tweet Count > Next
  6. Select ‘Load the data into new tables with this prefix:’ and enter prefix ‘SEC_Twitter’ > Next > Next > Finish

insights_for_twitter_sec_finished

Using public SEC data via DashDB:
https://www.sec.gov/dera/data/financial-statement-data-sets.html
Download the SEC file for 2016Q3: 2016q3.zip

  1. Unzip the ‘2016q3.zip’ archive,
  2. Load the 4 *.txt files: num, pre, sub, tag,
  3. Load > Load from Desktop > drop the file into the upload window,
  4. Change the separator character to ‘tab’,
  5. Don’t check the ‘Does the file have columns that contain dates or times? Yes No’, this may break the dataload sometimes, as the data is not always 100% cleaned correctly,
  6. Rename the tables so they have the prefix ‘SEC_2016Q3_’.

Other datasets:

  • Pitney Bowes Geodata:
    1. Add the Pitney Bowes service to your Bluemix application
    2. Get AccessToken using OAuth2:
      curl -X POST -H "Authorization: Basic a2t2eetceteratVA==" -H "Content-Type: application/x-www-form-urlencoded" -d 'grant_type=client_credentials' "https://api.pitneybowes.com/oauth/token"
    3. Then call the PB service:
      curl -X GET -H "Authorization: Bearer vc84ZaccesstokenoK2" "https://api.pitneybowes.com/location-intelligence/geolife/v1/demographics/byaddress?address=550%20W%2054th%20St%2C%20New%20York%2C%20NY%2010019&country=USA"
  • WeatherCompany Data:
    1. Add the WeatherCompany Data service to your Bluemix application,
    2. Get the username and password from the credentials,
    3. Daily Forecasts:
      curl -X GET "https://<username>:<password>@twcservice.mybluemix.net/api/weather/v1/geocode/33.40/-83.42/forecast/daily/10day.json?units=m&language=en-US"
    4. Current Conditions:
      curl -X GET "https://<username>:<password>@twcservice.mybluemix.net/api/weather/v1/geocode/33.40/-83.42/observations.json?language=en-US&units=m"
    5. Almanac (Historic Data):
      curl -X GET "https://<username>:<password>@twcservice.mybluemix.net/api/weather/v1/geocode/33.40/-83.42/almanac/monthly.json?start=01"

Creating a Java-Liberty App with Watson AlchemyAPI, CloudantDB and D3js

Requirements:

  • Git
  • Github account
  • Java
  • Eclipse for J2EE
  • WebSphere Liberty with JavaEE7
  • WebSphere Liberty plugin for Eclipse
  • Add *.cloudant.com.crt to the WepSphere Liberty Profile (wlp) server’s Java Key Store (JKS)
  • Optional: WAS AdminCenter 1.0
  • Optional: Maven

Steps:

  1. Create the StarterApp
  2. Add the Toolchain or Continuous Integration (CI)
  3. Setup Localhost
  4. Add JSPs and Servlet for News Search
  5. Add REST API that calls the AlchemyData News API
  6. Save the AlchemyData News Search Results in CloudantDB
  7. Add a D3js Sentiment Score Graph
  8. Configure the CloudantDB for Querying
  9. Show History of Search Results

1. Create the StarterApp

  1. Sign in to Bluemix.net,
  2. Go to Catalog,
  3. Under ‘Boilerplates’, click the ‘Java Cloudant Web Starter’,
  4. For ‘App name’ and ‘Host name’ enter ‘<username>-liberty-watson’,
  5. Click the ‘Create’ button,
  6. In ‘Application Details’ click the ‘Overview’ link,
    bluemix_application_details
  7. Review the application configuration,
  8. Click ‘Connections’ and click ‘Connect New’ to create the following services:
  9. If no AlchemyAPI service already exists, create a new AlchemyAPI service by clicking the ‘Connect New’ button,
  10. from the Catalog, filter by ‘Watson’, select the AlchemyAPI service, click the ‘Create’ button, and click ‘Restage’
  11. Note: by default you can only create 1 instance of the AlchemyAPI service under your organization in a single space, creating a second instance or connecting an existing service in another space will cause an error. If an instance already exists, click the ‘Connect Existing’ instead, select the existing AlchemyAPI service and click the ‘Connect’ button, click ‘Restage’,

2. Add the Toolchain or Continuous Integration (CI)

Continue reading

Creating Sentiment Line Chart for the News with Watson, Python, and D3js

Requirements:
You must have Python installed. Check to see if you have Python installed from the commandline:
python --version

Table of Contents:

  1. Create a Starterapp
  2. Git Clone and Setup
  3. Create Additional Folders and Files
  4. Commit and Push Changes to Repository, Build and Deploy
  5. Create an AlchemyAPI service
  6. Create a Cloudant NoSQL service
  7. Add the Basic Workflow for Request-Response
  8. Get News using AlchemyAPI
  9. Create Helper Functions
  10. Save Responses in Cloudant
  11. Parse Response for D3js
  12. Draw the Line Chart in D3js

You can import AlchemyAPI requests into Postman with this Postman collection.

The source code for the application can be viewed or cloned from Github.

1. Create a Starterapp

  1. Go to Catalog > Boilerplates
  2. Click the ‘Python Flask’ starterapp
  3. For name enter <username>-newssentiment
  4. Go to Overview
  5. Under ‘Continuous Integration’ click ‘Add GIT Repo and Pipeline’ to add a DevOps platform, select ‘Populate the repo with the starterapp packageand enable Build & Deploy pipeline’ > Click Continue > Click ‘CLOSE’.
  6. Click ‘EDIT CODE’.
  7. The very first time you login to the ‘DevOps’ environment you will need to pick a username for the ‘DevOps’ environment.
  8. In the left menu of icons, click the top folder icon, and click ‘Git URL’ to copy the Git repository url.
  9. If you prefer to edit in the online editor in Bluemix, click ‘EDIT CODE’ button and then click the second pencil icon in the left menu of icons.
  10. I will continue to work on localhost instead.

Continue reading

Easy Web Application Development for Beginners with Node-RED

Objective

The objective of this tutorial is to create two applications: a Node.js application that functions as a web client, and a Node-RED application that functions as the server. You will create an input form in the client that lets a user send a registration request to a server. The server will save the registration in a database and send a spoken response back to the client using IBM Watson’s Text to Speech service.

Requirements

You must have access to a Bluemix account.

1. Create a Client Application with SDK for Node.js

First, I will create a Node.js web application, which will function as our client and we will create web pages to ask for user input. Technically, this client application is also running on a server, so it is perhaps confusing to call it a client, but in our scenario and architecture, this client application functions as the user interface that initiates the request to a processing server.

  1. Go to http://bluemix.net and click to ‘LOG IN’ button to log into your Bluemix account,
  2. If this is the first time you log in, Bluemix will ask to create an organization and a space. You can create multiple spaces, for instance a different space for each
  3. Click the ‘CATALOG‘ menu on the top right of the page,
  4. To create a Node.js based application with the ‘SDK for Node.js’, find the ‘SDK for Node.js’ in the ‘Runtimes’ section and click the icon,
    bluemix-catalog-nodejs
  5. Continue reading