Temporary URL to access objects in Object Storage in IBM Bluemix using Python Swift Client

The Object Storage service is based on OpenStack Swift and can be accessed by using any compatible client application (CloudBerry/CyberDuck/Python Swift Client).

This blog describes how to create a temporary URL to access files/objects in the Object Storage using Python Swift Client without requiring further authentication.

 Prerequisites:

Install Python 2.7 or later(currently it doesn’t support Python 3.0)

Install setuptools on Windows by following the documentation provided on the setuptools website (https://pypi.python.org/pypi/setuptools) For MAC, it is pre-installed

  • Ensure that the C:\Python27\Scripts directory is defined in the PATH environment variable, and use the easy_install command from the setuptools package:  C:\>easy_install pip
  • Install the Python Swift client by using Python pip: sudo pip install python-swiftclient
  • Install the Python Keystone client by running the following command: sudo pip install python-keystoneclient
  • Next step is setting up the client:

                   The Swift client takes the authentication information from the following environment variables:

                   Set the authentication information as follows.

                   export OS_USER_ID=<user_id>

                   export OS_PASSWORD=<password>

                   export OS_PROJECT_ID=<project_id>

                   export OS_AUTH_URL=https://identity.open.softlayer.com/v3

                   export OS_REGION_NAME=dallas

                   export OS_IDENTITY_API_VERSION=3

                   export OS_AUTH_VERSION=3

(You can find the <user_id>,<password>,<project_id> for your Object Storage service from the Service Credentials page in the Object Storage user interface in Bluemix Dashboard)

  • After that, Identify your authentication account by Swift stat command : swift stat

             (Locate the Account field and note the full string behind Account: including AUTH_)

  • Set a secret key by typing the command: swift post -m “Temp-URL-Key:<key>”

          Ex: swift post -m “Temp-URL-Key:10908765432”

           This key can be anything (a long, random, and hard to guess string is preferred)

               Run the Swift stat command to verify that the Temp-URL-Key is set successfully: swift stat

  • Create the temporary URL using the command: swift tempurl GET <seconds> <path> <key>

             Ex: swift tempurl GET 360 /v1/AUTH_e7ddd86303d940ff8372938c41169925/store1/bookshelf.jpg 10908765432

             GET allows download. PUT allows upload.

             Time in seconds that the temporary URL will be available.

             The full path of the object expressed as /v1/<auth_account>/<container_name>/<object_name> (auth_account is the detail, you had got after swift stat command)

             The key that you set in the previous step.

  • This command will return a URL.

             Eg of URL: /v1/AUTH_e7ddd86303d940ff8372938c41169925/store1/bookshelf.jpg?temp_url_sig=92633b82c0f92d91923088aaa5cb22af29e979bf&temp_url_expires=1475489383

  • Append the URL to the region you use Object Storage and then use the full URL to download the object with any compatible HTTP client such as curl, wget or Firefox

         If it’s DALLAS region, https://dal.objectstorage.open.softlayer.com/

        & if it’s London region, https://lon.objectstorage.open.softlayer.com/

Watson powered Slackbot that helps you with language translation

Have you ever got lost in a new city not knowing the language or have you got stuck with your French/Spanish classes/homework? This simple Slackbot powered by Watson Conversation and Language Translator, translates language and helps you understand them faster & better by conversing!

imageIt is a simple Slackbot that can translate from English to French, French to English and Spanish to English(more translations are possible since Watson Language Translator supports Arabic,French,Spanish and Portugese). The Slackbot identifies the intent of natural language input through Watson Conversation and responds with the translated language.

Steps to build this Slackbot is available here http://bit.ly/2lM5hye

How to get stored images/videos from Object Storage in IBM Bluemix

screen-shot-2016-09-06-at-9-56-25-pm

What is Object Storage?

IBM® Object Storage for Bluemix® provides you with access to a fully provisioned Swift Object Storage account to manage your data. Swift provides a fully distributed, API-accessible storage platform. You can use it directly in your applications or for backups, making it ideal for cost effective, scale-out storage.

This blog will help you to get images/videos from Cloud Data Storage(Object Storage) into your application.

Prerequisites

Below shown is the UI of Object Storage. I have 4 images & 1 video uploaded to a container named store1.

screen-shot-2016-09-06-at-10-01-03-pm

Front end of the application:

screen-shot-2016-09-06-at-10-05-31-pm

Code to get the image/video from Object Storage

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

// TODO Auto-generated method stub

String imgoption = request.getParameter(“imgOpt”); //Takes the user input

String envApp = System.getenv(“VCAP_APPLICATION”);

String envServices = System.getenv(“VCAP_SERVICES”);

System.out.print(envServices);

JSONParser parser = new JSONParser();

try{

Object obj = parser.parse(envServices);

JSONObject jsonObject = (JSONObject) obj;

JSONArray vcapArray = (JSONArray) jsonObject.get(“Object-Storage”);

JSONObject vcap = (JSONObject) vcapArray.get(0);

JSONObject credentials = (JSONObject) vcap.get(“credentials”);

String userId = credentials.get(“userId”).toString();

String password = credentials.get(“password”).toString();

String auth_url = credentials.get(“auth_url”).toString() + “/v3”;

String domain = credentials.get(“domainName”).toString();

String project = credentials.get(“project”).toString();

Identifier domainIdent = Identifier.byName(domain);

Identifier projectIdent = Identifier.byName(project);

OSClientos = OSFactory.builderV3()

.endpoint(auth_url)

.credentials(userId, password)

.scopeToProject(projectIdent, domainIdent)

.authenticate();

System.out.print(os);

SwiftAccount account = os.objectStorage().account().get();

ObjectStorageService objectStorage = os.objectStorage();

List<? extends SwiftContainer> containers = os.objectStorage().containers().list();

System.out.println(containers); // Prints the list of containers

List<? extends SwiftObject> objs = os.objectStorage().objects().list(“store1”);

System.out.println(obj); //Prints the list of objects inside the container store1

SwiftObject fileObj = objectStorage.objects().get(“store1”,imgoption);

System.out.println(fileObj);

String mimeType = fileObj.getMimeType();

DLPayload payload = fileObj.download();

InputStream in = payload.getInputStream();

response.setContentType(mimeType);

OutputStream out = response.getOutputStream();

IOUtils.copy(in, out);

in.close();

out.close();

}catch(Exception e){

e.printStackTrace();

}

}

Ensure that you have added the dependency to POM.XML file

  <dependencies>

  <dependency>

  <groupId>org.pacesys</groupId>

  <artifactId>openstack4j</artifactId>

  <version>3.0.0</version>

</dependency>

<dependency>

    <groupId>org.apache.directory.studio</groupId>

    <artifactId>org.apache.commons.io</artifactId>

    <version>2.4</version>

</dependency>

<dependency>

<groupId>javax.servlet</groupId>

<artifactId>javax.servlet-api</artifactId>

<version>3.1.0</version>

<scope>provided</scope>

</dependency>

<dependency>

    <groupId>com.googlecode.json-simple</groupId>

    <artifactId>json-simple</artifactId>

    <version>1.1</version>

</dependency>

</dependencies>



<build>

    <plugins>

        <plugin>

            <groupId>org.apache.maven.plugins</groupId>

            <artifactId>maven-compiler-plugin</artifactId>

            <version>3.1</version>

            <configuration>

                <source>1.8</source>

                <target>1.8</target>

            </configuration>

        </plugin>

    </plugins>

  </build>

 

Please note that OpenStack4j has some of the same libraries that are also provided in the Liberty profile if you are running this Java application on Bluemix. To avoid this you should use reverse class loading or exclude jaxrs from the enabled features. 

This is a Java app which was deployed on a Node.JS runtime.

Output of the app:

Video & Image

 

Hashtag sentiment Analyzer using Node-RED,Cloudant, dashDB,R script

2

Twitter Node Configuration:7

Switch Node Configuration:

3

Not so positive function node configuration:

4

Positive sentiment Function Node configuration:

5

Cloudant Node Configuration:

6

Once after wiring the nodes, click on DEPLOY ( top right corner of Node-RED).

Launch Cloudant and then you will find your database in the list

8

Create a dashDB warehouse to graphically analyze the sentiment

9

Goto dashDB and then run R script

10

Rscript.PNG

Data has been graphically analyzed using R Scripts.

1

1 represents Positive sentiment and 0 represents not-so-Positive sentiment

 

Web app using Java & Cloudant NoSQLDatabase in IBM Bluemix

IBM® Bluemix™ is the Platform as a Service(PaaS) cloud offering from IBM®. It enables organizations and developers to quickly and easily create, deploy, and manage applications on the cloud. Bluemix delivers enterprise-level services that can easily integrate with your cloud applications without you needing to know how to install or configure them.

IBM® Cloudant® NoSQL Database for Bluemix® is a NoSQL database as a service (DBaaS). It’s built from the ground up to scale globally, run non-stop, and handle a wide variety of data types like JSON, full-text, and geospatial. Cloudant NoSQL DB is an operational data store optimized to handle concurrent reads and writes, and provide high availability and data durability.

This tutorial will help you to build and deploy a java application that inserts registration details to Cloudant NoSQLDB

Prerequisites

Let’s start building the java application,before that lets go to our Bluemix Catalog and select required services to build it!

Step 1: Goto Catalog and then click on Java Runtime

blog_2

Step 2: Enter your application name. Eg: samplecloudant as shown in the image below. Click on CREATE

Step 3: Application has been created and it can be viewed on the Bluemix DASHBOARD. Click on the application

Step 4: Click on ADD SERVICE in the application(samplecloudant) DASHBOARD

Step 5: In CATALOG goto Data and Analytics and click on Cloudant NoSQL DB

Step 6: Change the Service name of Cloudant NoSQL DB to myCloudant and click on CREATE.

The service is now up and running in Bluemix! We can now proceed to Eclipse IDE to build the registration application that inserts details into Cloudant NoSQL Database.

We will be creating this web application using a Maven project in Eclipse(it is the easiest way to retrieve the dependencies we need — the ektorp client jars).

Step 7: Open Eclipse and create a new Maven project

Set the following values

  • Group ID: com.register
  • Artifact ID: registerblue
  • Version: 1
  • Packaging: war
  • Leave everything else as-is and Click Finish

 

 

Copy dependencies into pom.xml inside <project>

<dependencies>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.ektorp</groupId>
<artifactId>org.ektorp</artifactId>
<version>1.4.1</version>
<scope>provided</scope>
</dependency>
</dependencies>

Create a servlet

  • Click on registerblue>src>main>java
  • Right click on register folder and then New > (Other) > Web > Servlet
  • Keep class name as RegisterServlet & package name as com and then click on Finish

In web.xml

<servlet>
<display-name>RegisterServlet</display-name>
<servlet-name>RegisterServlet</servlet-name>
<servlet-class>com.RegisterServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>RegisterServlet</servlet-name>
<url-pattern>/RegisterServlet</url-pattern>
</servlet-mapping>

In RegisterServlet.java ( Resource Injection)

@Resource(name = “couchdb/myCloudant”)
protected CouchDbInstance mydb ;

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub

response.setContentType(“text/html”);
response.sendRedirect(request.getContextPath() + “/success.jsp”);

String name=request.getParameter(“name”);
String emailid = request.getParameter(“emailid”);
String mobile = request.getParameter(“mobile”);
String company=request.getParameter(“company”);
String loc=request.getParameter(“loc”);

String dbname = “registerdb”;
try {
//creates a database with the specified name
CouchDbConnector dbconnector = mydb.createConnector(dbname, true);
//create a document to place into your new database
Map<String, Object> doc = new HashMap<String, Object>();
doc.put(“_id”, UUID.randomUUID().toString());
doc.put(“name”, name);
doc.put(“emailid”, emailid);
doc.put(“mobile”, mobile);
doc.put(“company”, company);
doc.put(“location”, loc);

dbconnector.create(doc);
} catch (Exception e) {
response.getWriter().println(e.getMessage());
}
}

Export the WAR file and push it into bluemix using Cloudfoundry command line interface.

Once the application has started,insert the details through registration page.

To view the inserted details,click on the Cloudant service that is bound to your application.

Click on LAUNCH, it will take you to database list,you can now find your database registerdb in the list.

Click on registerdb and then you can view your documents on the right side.

You can create a view in Design Documents section and then copy paste API URL(top right) to view the documents in the browserdetails

Courtesy:IBM Bluemix and Cloudant NoSQL DB!

Weather Notification App using IBM Insights for Weather, Node-RED and Twilio in IBM Bluemix

 

IBM® Bluemix™ is the Platform as a Service(PaaS) cloud offering from IBM®. It enables organizations and developers to quickly and easily create, deploy, and manage applications on the cloud. Bluemix delivers enterprise-level services that can easily integrate with your cloud applications without you needing to know how to install or configure them. Bluemix provides a dashboard for you to create, view, and manage your applications and services as well as monitor your application’s resource usage. Bluemix dashboard also provides the ability to manage organizations, spaces, and user access.

IBM Insights for Weather service lets you retrieve weather data for an area specified by a geolocation. The data allows you to forecast, detect, and visualize disruptive weather events that might affect decision making in your application.

Node-RED is a tool for wiring together hardware devices, APIs and online services in new and interesting ways.Node-RED provides a browser-based flow editor that makes it easy to wire together flows using the wide range nodes in the palette. Flows can be then deployed to the runtime in a single-click.JavaScript functions can be created within the editor using the a rich text editor.A built-in library allows you to save useful functions, templates or flows for re-use.

Twilio is a mobile service that is available on Bluemix which allows software developers to programmatically make and receive phone calls and send and receive text messages using its web service APIs.

This tutorial will help you build a weather notification app that will send you weather update every morning and necessary precautions you have to take to save you from daily weather.

Prerequisites

Step 1: Create a Node-RED service in Bluemix and then bind Insights for Weather and Twilio Service

2

Step 2: Click on Environment Variables(visible in the left side) and then make note of weather insights username and password in a Notepad

3

Step 3: Goto https://twcservice.mybluemix.net/rest-api/ and click on twc_observations_current

4

Step 4: Change the geocode according to your geography and then scroll down

5

Step 5: Click on Try it out! You would be prompted to enter the username and password.Enter it from the notepad

6

Step 5: Save the Request URL, you will require that subsequently

7

Step 6: Goto the Bluemix App URL and then click on Node-RED flow editor. Start dragging in the nodes. You will require

  • Inject Node
  • Http Request Node
  • JSON node
  • Function node
  • Twilio node and
  • Debug node

Let’s configure each node and then wire them accordingly!

Inject node: It will be triggered, every day 6:00AM thereby sending weather notification SMS

trigger.PNG

Http Request Node:

Enter the REQUEST URL, Click on Basic Authentication and then enter the Weather insights credentials

http_request

JSON Node: It will convert the output string from Http Request to JSON format which is fed into a function

json.PNG

Output of JSON node:

json_output.PNG

Function node: Write a function to extract the value

function

Twilio node: Insert the twilio credentials, To number to receive the Notification

twilio.PNG

You can add a debug node to understand whether it is functioning properly.

Click on Deploy button which is in the top right corner and then click on the left side of the Inject node to trigger.

Yipee! I just received a notification!! 🙂 You can schedule to receive it everyday morning!

13235034_1082577601799736_714966582_o

Courtesy:IBM Bluemix™(bluemix.net), Twilio, Weather Insights and Node-RED

Single Sign On(SSO) for Bluemix Web Apps

SSO_logo2

IBM® Bluemix™ is a Platform as a Service(PaaS) cloud offering from IBM®. It enables organizations and developers to quickly and easily create, deploy, and manage applications on the cloud.

IBM Single Sign ON is a policy based authentication service that provides an easy to embed Single SIGN ON capability for NODE JS Or Java Applications.

Single SIGN ON supports several identity sources where users credentials are stored:

  • SAML Enterprise: A user registry with an exchange of SAML token that completes the authentication.
  • Cloud Directory: A user registry that is hosted in the IBM Cloud
  • Social Identity Sources: The user registries that are maintained by Google,Facebook and LinkedIn

This blog will help you to ADD SOCIAL IDENTITY SOURCE FROM FACEBOOK for Single SIGN ON (SSO) for Bluemix App

Prerequisites

So,let’s begin with CONFIGURING IDENTITY SOURCES :

Step 1: From Bluemix CATALOG, Select Single Sign On Security service

1

Step 2: Insert a Service Name and then click on CREATE

2

Step 3: Provide a name to the service. This name will be part of the service URL and Click on Continue

3

Step 4: Click FACEBOOK to add identity source.

4

Step 5: After changing the name (optional), Click on “Click here” which will redirect you to facebook for developers page.

5

Step 6: Click on My Apps and then click on Add a New App

6

Step 7: Click on Website

7

Step 8: Enter App Name and then Click on Create New Facebook App ID

8

Step 9: Choose a Category and then click on Create APP ID

9

Step 10: You can now see your App listed on My Apps section. Click on TweetAuth which will take you to Dashboard of the App

10

Step 11: In the Dashboard, Copy APP ID and APP Secret

11

Step 12: Go back to Bluemix Dashboard and then Paste the APP ID and APP Secret. Copy the OAuth Redirect URI and then Click on SAVE

12

Step 13: In the facebook for developers page, SETTINGS TAB>Basic enter your Contact Email and Website URL and click on SAVE CHANGES

13

Step 14: In Facebook for developer page, SETTINGS>ADVANCED, toggle from NO to YES for Client OAuth Login and then paste the OAuth Redirect URI in the textbox and then click on SAVE CHANGES

14

Step 15: Go back to Bluemix DASHBOARD, you will now find VERIFY button,click on that and Verify Access to Facebook by clicking on “Click here”

15

Step 16: Awesome! It’s working!!

15-b

Step 17: You can now see your identity source app in the list

16

The next step is to Configure APP by creating an APP:

Configuring a Liberty for Java APP with SSO:

  • For Liberty for Java Applications, the Single Sign On service leverages the OpenID Connect (OIDC) client feature from Liberty and the Bluemix Liberty buildpack. As a result, Java applications running on Bluemix do not need to include any code to support the OpenID Connect protocol or Single Sign On.
  • However, you must enable security constraints. To enable them, you can use declarative J2EE security to secure the application and all protocol support is completely “built-in.”

    After you bind the app to an instance of the single sign-on service, the Bluemix buildpack detects that the application is bound and automatically configures the OIDC client in the Liberty runtime server.xml to enable the application for the service. The configuration is done when you deploy the application in Bluemix using either the cf push command or using the restaging process in the Bluemix dashboard.

    To complete the configuration of the application, you must add security constraints. You can add the constraints in the same manner as you would for traditional J2EE applications using EAR/WAR binding files to declare roles and protected resources.

    The following example illustrates security constraint configuration for a Java application that uses the web.xml and the Liberty server.xml files.

  • Create a HelloWorld Servlet in com package with twitter as the Java application name
  • Open the web.xml file in a text editor.
  • Set security constraints: Consider the below as example.
<servlet>
    <servlet-name>HelloServlet</servlet-name>
    <servlet-class>com.HelloWorld</servlet-class>
    </servlet>
    <servlet-mapping>
    <servlet-name>HelloServlet</servlet-name>
    <url-pattern>/hello/*</url-pattern>
    </servlet-mapping>
    
    <security-constraint>
    <display-name></display-name>
    <web-resource-collection>
      <web-resource-name>HelloServlet</web-resource-name>
      <url-pattern>/</url-pattern>
      <url-pattern>/*</url-pattern>
      <url-pattern>/</url-pattern>
      <http-method>GET</http-method>
      <http-method>PUT</http-method>
      <http-method>HEAD</http-method>
      <http-method>TRACE</http-method>
      <http-method>POST</http-method>
      <http-method>DELETE</http-method>
      <http-method>OPTIONS</http-method>
    </web-resource-collection>
    <auth-constraint>
      <role-name>TESTROLE</role-name>
    </auth-constraint>
  </security-constraint>

  • Save the web.xml file.

 

  • Open the server.xml file in a text editor.
  • Enable the security constraints. Use the following example as a guide.
    <server description="new server">
    <featureManager>
    <feature>jsp-2.2</feature>
    <feature>localConnector-1.0</feature>
    </featureManager>
    <httpEndpoint httpPort="9080" httpsPort="9443" id="defaultHttpEndpoint"/>
    <applicationMonitor updateTrigger="mbean"/>
    <application type="war" id="twitter" name="twitter"
    location="twitter.war">
    <application-bnd>
    <security-role name="TESTROLE">
    <special-subject type="ALL_AUTHENTICATED_USERS"/>
    </security-role>
    </application-bnd>
    </application>
    </server>

  • Push the app(twitter.war) along with server.xml to Bluemix using CF Push command . Learn how to push application to bluemix using CF command through my earlier blog.
  • Bind the SSO service to the Java APP and then Restage it.
  • Open the app .Here eg: tweetout.mybluemix.net/twitter/hello ,It will redirect you to facebook page for logging in

Hurray your Bluemix App is now secured by Single Sign On facebook authentication!!

 

 

Courtesy: (bluemix.net) IBM Bluemix and Facebook for Developers (developers.facebook.com)

Java application to send mail using Sendgrid & IBM Bluemix

IBM® Bluemix™ is the Platform as a Service(PaaS) cloud offering from IBM®. It enables organizations and developers to quickly and easily create, deploy, and manage applications on the cloud. Bluemix delivers enterprise-level services that can easily integrate with your cloud applications without you needing to know how to install or configure them.

SendGrid provides a cloud-based email delivery service that assists businesses with transactional email management while abiding by anti-spam regulations. The service manages various types of email including shipping notifications, friend requests, sign-up confirmations, and email newsletters.

This tutorial will help you to build and deploy a java application that sends registration successful mail using SendGrid and IBM® Bluemix™

Prerequisites

Let’s start building the java application,before that lets go to our Bluemix Catalog and select required services to build it!

Step 1: Goto Catalog and then click on Java Runtime

blog1

Step 2: Enter your application name. Eg: mailreg as shown in the image below. Click on CREATE

4

Step 3: Application has been created and it can be viewed on the Bluemix DASHBOARD. Click on the application

5

Step 4: Click on ADD SERVICE

6

Step 5: In CATALOG goto Web and Application and click on SendGrid

7

Step 6: Change the Service name if required and click on CREATE

8

Step 7: Click on Add a service again and then in CATALOG goto Data and Analytics and click on SQLDB

blog_6

Step 8: Create the service by giving it a service name. Follow the steps to create a table in SQLDB as shown in my previous blog

The service is now up and running in Bluemix!! We can now proceed to Eclipse IDE to build the registration application that inserts details into database and also sends out registration successful mail.

Please ensure that you Copy and paste the SendGrid-java jar to the below shown location

10

Please refer to my previous blog to understand how to add data to SQL database and append the piece of code(shown below) to send mail upon successful completion of registration

import com.sendgrid.*;

public class SendGridExample {
  public static void main(String[] args) {
    SendGrid sendgrid = new SendGrid("sendgrid_username","sendgrid_password");;
//OR
    SendGrid sendgrid = new SendGrid("SENDGRID_APIKEY");

 SendGrid.Email email = new SendGrid.Email();   
 email.addTo("xxxxxxx@gmail.com"); //Can programatically add sender's email id!  
 email.setFrom("noreplybluemix@gmail.com");  
 email.setSubject("Thank You for registering for Email services");  
 email.setHtml("<h1>Thank You for registering for Email Services!</h1>");
 email.setText("Thank You for registering for Email Services!");

  SendGrid.Response response = sendgrid.send(email);  } } 

You can add attachment to the mail & there are more options apart from these!

Push the application to Bluemix(refer my previous blog) and on successful 
registration you will receive a mail in your inbox as shown below

OUTPUT:

Output

Integrating mail services had never been this easy! 
Thanks to IBM Bluemix and SendGrid!

Courtesy: (bluemix.net) IBM Bluemix and SendGrid (sendgrid.com)

Simple application using Node-RED Starter(SDK for Node js, Cloudant NoSQL database) in IBM Bluemix

bluemix1

IBM® Bluemix™ is the Platform as a Service(PaaS) cloud offering from IBM®. It enables organizations and developers to quickly and easily create, deploy, and manage applications on the cloud. Bluemix delivers enterprise-level services that can easily integrate with your cloud applications without you needing to know how to install or configure them. Bluemix provides a dashboard for you to create, view, and manage your applications and services as well as monitor your application’s resource usage. Bluemix dashboard also provides the ability to manage organizations, spaces, and user access.

Node-RED is a tool for wiring together hardware devices, APIs and online services in new and interesting ways.Node-RED provides a browser-based flow editor that makes it easy to wire together flows using the wide range nodes in the palette. Flows can be then deployed to the runtime in a single-click.JavaScript functions can be created within the editor using the a rich text editor.A built-in library allows you to save useful functions, templates or flows for re-use.

In IBM® Bluemix™, a boilerplate is a container for an application and its associated runtime environment and predefined services for a particular domain. You can use a boilerplate to quickly get up and running. The Node-RED Starter boilerplate has Node-RED,Cloudant databse and Monitoring and Analytics Services as a combo pack.You don’t have to spend time in adding or binding services.

The steps below will help you to build a simple twitter feed application and insert those tweets into Cloudant database with the Node-RED Starter boilerplate.

Prerequisites

Step 1: Choose the Boilerplate Node-RED Starter from the CATALOG tab1.2

Step 2: Input the host name and click on CREATE

1.1

Step 3: Hurray! The application is created with Cloudant NoSQL DB and SDK for Node js

blog2

Step 4: One instance of the application is running perfectly! Click on the URL

blog3Step 5: Click on the button Go to your Node-RED flow editor


3

Step 6: The Node-RED page opens up with the nodes for each functionality on the left side


4.1

Step 7: Drag and drop the twitter node to the sheet1 (ensure you drag and drop the correct node)

twitter

Step 8: Double click on the twitter node and enter the required fields(ensure that you authenticate it with your twitter id) and click Oktwitter3Step 9: Drag and drop debug node in sheet 1


debug

Step 10: Enter the required field as shown below

debug2

Step 11: Drag and drop cloudant node to sheet1(ensure that you have choosen the correct node)

cloudant

Step 12: Double click the node and enter the required details

cloudant2

Step 13: Wire the nodes from its node points and click on DEPLOY

out

Step 14:Yes,now you can see live tweets for the hastag #bluemix on your debug console!!

output

Step 15: Goto the cloudant database

cloudb

Step 16: Click on Launch

cloud1

Step 17: You can see the database (tweets) ! Click on it. 

cloud2

Step 18: You can see the documents with unique id and _rev

we

Step 19: Click on one of the document and you can see the tweet,date,time,created by whom and all other details in JSON format.

out2

You can use the documents inserted in the Cloudant NoSQL database for further use and Yes,the application was ready within few minutes! That’s the power of Node-RED in IBM Bluemix. You can drag and drop other several nodes which are available in Node-RED to make this a better application(for analysis,for sending notifications etc)

Thanks to Node-Red,Cloudant NoSQL database and IBM Bluemix! You just saved our time from writing 1000 lines of code!

Courtesy: IBM Bluemix, Node-RED, Cloudant NoSQL Database