Bluemix Node Red Natural Language Classifier Website - ibm-cloud

I want to change my index.html page to display my Node Red flow. How do I add the HTTPRequest->Template->HTTPResponse sequence to NLC flow?
The following Node Red flow displays in debug mode only. https://github.com/watson-developer-cloud/node-red-labs/blob/master/basic_examples/natural_language_classifier/nlc_flows.json
Also see for more general instructions: https://github.com/watson-developer-cloud/node-red-labs/tree/master/basic_examples/natural_language_classifier

You will need to change the output from the HTTP Request to return a json object. Once you do, then this template will display everything that the Watson NLC service outputs
<h1>Watson NLC Output</h1>
{{#payload}}
<div><span>Classifier ID : </span><span>{{classifier_id}}</span></div>
<div><span>Question : </span><span>{{text}}</span></div>
<div><span>Top Class : </span><span>{{top_class}}</span></div>
<div>
<h2>Classes</h2>
{{#classes}}
<div><span>{{class_name}} : </span><span>{{confidence}}</span></div>
{{/classes}}
</div>
{{/payload}}

Related

Service schema is not detecting into Rich Results Test?

I have added a service schema on my site. However, while testing into the Rich Result Tool, it's showing the Local business schema instead of the service schema. But it is still showing service schema into the Structure Testing Tool
Rich Result Tool - https://a.cl.ly/ApuG1mG4
Structure Testing Tool - https://a.cl.ly/4guOD8lZ
Is the service schema is supported by Google or not? If yes where we can see the result into Rich result?
The Rich Results Test only reports top level entities that generate Rich Results in Google. Service is not one of them.
LocalBusiness is a supported entity. Because of this the tool is promoting it to the top level in its report.
You can see this effect on any entities that have their own rich results. e.g. an aggregateReview might be in a product, but it gets reported on at the top level as it has its own snippet (stars).
In case it helps anyone interesteed in this topic.
For some time the validation tool for structured data from google needs a context and also theschema.org documentation specifies it... He estado luchando con eso durante aproximadamente una hora until I saw it and I fixed it adding:
"#context":"https://schema.org"
just before the rest of the schema:
The result:
<script id="jgc-structured-data" type="application/ld+json">
{
"#context":"https://schema.org",
"#type":"Organization",
"name":"Juan G Carmona",
"legalName":"Juan G Carmona",
"url":"https://jgcarmona.com",
"logo":"https://jgcarmona.com/img/jgc-log-w.png","
foundingDate":"1981",
"address":{
"#type":"PostalAddress",
"addressLocality":"Paracuellos de Jarama",
"addressRegion":"Madrid",
"postalCode":"28061",
"addressCountry":"Spain"
},
"contactPoint":{
"#type":"ContactPoint",
"contactType":"customer service",
"email":"juan#jgcarmona.com"
},
"sameAs":[
"http://www.linkedin.com/in/juangarciacarmona",
]
}
</script>

how to extract parameters from Jmeter for web forms using redirection

Hi so my webform navigates from : http://43.252.88.109:4006/BracketICT/?t=aZCcbzidJJKfFgrkk1RYPH0zHTl+MtTuoGeiUw0hEw48nLZUoPrfntO29VV2daEiR3cPbu25/Xf2a3Q1UMZs1tAoUDti4wBVbYQbRHhhBDTt0Z1yTrWlkWKunP18DkVBkRSSVMdiHYyQ=&uniqueID=dGdck61pZFirpz9fA5FQZFhakSeoICZ9&dev=1696661 to
http://43.252.88.109:4006/BracketICT/examstart.aspx
]3
i.e. from the instructions page to exam start page on the click of ![the exam start button. My Jmeter response during recording shows that the link: http://43.252.88.109:4006/BracketICT/examstart.aspx
accepts two parameters i.e. attemptid or recordid. These values are generated on the location parameter of the examstart screen when the user clicks on starts test and lands on exam page. My response for http://43.252.88.109:4006/BracketICT/examstart.aspx does not show the location parameter on JMeter. How do i extract attempt id or recordid dynamically in this case during redirection ?]5
You need to:
Expand the 3rd sample result from the top in the View Results Tree listener
Switch to "Response Headers" tab
there you should be able to see the Location header and you will be able to extract these attemptid and recordid values using Regular Expression Extractor

Node-RED and REST APIs with resource id's

I'm trying to use Node-RED to develop a REST based API. For example, a GET would be:
http://myurl.com/widgets/"widget-id"
where "widget-id" would be 123. I can get this to work using query strings. However, I can't seem to figure out what to put on the http input node to allow a resource id to get passed. Am I missing something obvious? Any ideas on what I need to do?
The other answer is nearly right, it just needs tweaking for Node-RED
If you set the URL in the HTTP Input node to /widget/:id
you can access the widget id in a function node linked to the HTTP Input node as follows:
var id = msg.req.params.id;
if you get all widgets:
router.get('/widgets/', function(data){});
if only one item(for example - 123):
router.get('/widgets/:id(\\d+)', function(data){});
in you're browser or if you using POSTMAN enter http url: http://youredomain.com/widgets/or http://youredomain.com/widgets/123

How to design complex update actions in REST API

I'm currently working on a REST API, trying to design it with most best practices as possible.
I work with Symfony2 PHP framework but some of my questions are valid for any REST API i guess.
Starting from the base design for a particular resource :
GET /resource - Get all resources
POST /resource - Create resource
GET /resource/{id} - Get resource with id={id}
PUT|PATCH /resource/{id} - Edit the resource with id={id}
DELETE /resource/{id} - Delete the resource with id={id}
Supposing my resource has complex rules while updating.
It has a "status" field, (a float for example), that can be updated only by following a particular scheme
It has a "schedule" field (a datetime), with different choices available that are not always the same
How am I supposed to expose those rules to the API consumer ? For the schedule field, how am I supposed to provide the different choices available at the current time ?
About the Symfony server-side part, I followed most of the recommandations of this walkthrough : http://williamdurand.fr/2012/08/02/rest-apis-with-symfony2-the-right-way/
My POST, PUT & PATCH actions are handled with Symfony Forms, so most of the rules are processed by Symfony constraints/validations features.
But form binding is quite limited, let's supposed I want to trigger a particular event if the user change the status field from 2 to 3? What is the best way to do that ?
Thanks in advance.
HTTP has another verb you aren't using: OPTIONS. You can use this to list the schedule options.
Here's a blog article about it: http://zacstewart.com/2012/04/14/http-options-method.html
As for updating the status, I would reuse POST and include an action in the field. Example:
POST
{
"type": "update",
"status": 3
}
Modified REST:
GET /resource - Get all resources
POST /resource - Create resource
GET /resource/{id} - Get resource with id={id}
PUT|PATCH /resource/{id} - Edit the resource with id={id}
DELETE /resource/{id} - Delete the resource with id={id}
OPTIONS /resource/{id} - Retrieve options of resource with id={id}
Keep in mind that you can pass params along in the body for everything but GET and you can pass any params in the URL for GET.
I have zero knowledge on Symfony2, so I'll just concentrate on your more generic REST how-to qustion about exposing rules.
Give the consumers of your REST API a documentation. It's the first thing they will hit before actually playing with your API. Use tools for that, from auto-generated help pages to 3'rd party providers like Apiary.io or alike.
Create meaningful responses when consumers send "wrong" requests: use correct http response status codes (Bad request, Conflict, etc.) when request parameters are missing or invalid.
If your REST api is relaxed, it can also include information about what went wrong and how to resolve the problem in the response body.
What worked well for me in the past was to have a generic ErrorMessage entity that was returned upon each non-successful request, containing a title, an error description, and a dedicated more technical "dev-description" which can be enabled/disabled for test/production on the server side.
In my case, my consumers all know that they can get either the expected response entity in case of success, or that generic ErrorMessage entity in the response in case of failure.
If you can desribe your rules, why not provide those as meta information for your service? Eg. in my case I know I have a set of parameters, each having a set of available options. Think of the parameters as the key in a query string, and the options as the values for that key. In a complex world, parameter options depend on other parameter options, eg. in my case the available options for parameter B are dependent of what option(s) are "selected" for parameter A. I can expose those dependencies by providing a "metadata" resource in my REST api, eg. a JSON stucture listing all parameters and all options for those parameters, and for each option adding a "requires" section desribing that that option is only "available" if parameter xy has selected option p and q.
This allows my consumers to - with a single request to that meta data resource - create a "state-machine" on the client side. I hope you get the picture.
Here is my understanding of REST-full way to handle updates and advertise update operations to API client.
This is based on this wonderful book and Fowler's article about REST with some additions of File Levels of Media Type and article about Restfull CQRS. Basically you use PUT for update and pass the operation via content type and advertise content type via mediaType in hypermedia controls.
All operations which are available for current state of your resource are listed among hypermedia controls which are passed with representation of resource like this:
<myresource>
<status>ACTIVE</status>
<some-field with-attribute="value"/>
<some-other-field/>
<!-- other fields representing state of resource -->
<link rel = "self"
uri = "/resource/1234"/>
<link rel = "/linkrels/resource/changeStatus"
uri = "/resource/1234"
mediaType = "application/vnd.myapp+xml;domain-model=ChangeStatusCommand"/>
<link rel = "/linkrels/resource/changeSchedule"
uri = "/resource/1234"
mediaType = "application/vnd.myapp+xml;domain-model=ChangeScheduleCommand"/>
<link rel = "/linkrels/help"
uri = "/help/resource"/>
</myresource>
Links together with mediaType gives enough information what command is allowed. In many cases this should be something very specific to current state of resource. For example if you can move it from status ACTIVE to TRASHED than command should be named not StatusChange but TrashCommand and so on.

Integrate AngularJS App with SoftwareAG webMethods Integration Server

I have been trying to set up a sample AngularJS app with webMethods Integration Server on the backend. Using $resource, I can easily pull normal JSON files and manipulate the data within the file. However, the goal is that I want to create services in webMethods Designer and call them from AngularJS using $resource to display the data in my app. The problem is that from AngularJS I cannot extract the data I need from the service that I'm creating in Designer. In Designer I can use (in WMPublic) documentToJSONString, and output something like:
jsonString {"id":"1", "name":"Dan", "quantity":"3"}
But I cannot extract the data because this is not a pure JSON string. Does anyone know how to (1) extract the JSON string output data using AnularJS or (2) output a JSON document from Designer? I am calling a REST service; something to the effect of
http://localhost:2222/rest/Get/getOrderData
from my services.js file in AngularJS.
Here is my services.js file:
/* Services */
var orderServices = angular.module('orderServices', ['ngResource']);
orderServices.factory('Order', ['$resource',
function($resource){
return $resource('http://localhost:2222/rest/REST/getOrderData', {}, {
query: {method:'GET', isArray:true}
});
}]);
Then, in my app, I want to use an ng-repeat to call things like {{order.id}}, {{order.name}} etc. Is anyone good with webMethods and Angular or done this before?
To force the response that you want, I would have used the service
pub.flow:setResponse mapping the jsonString to it's string parameter and probably hardcoded (eww!) the contentType parameter to 'application/json'
You may also need to use the service pub.flow:setResponseCode to set the response code.
They would be the last services in getOrderData
I would have invoked it using the below (where namespace is the folder structure in designer)
http://localhost:2222/invoke/namespace:getOrderData
The above applies to Integration Server V8 and it looks like you're using V9 since some of the services that you mention didn't exist in V8. This would also apply to a normal flow service, not a specific REST one (assuming they exist in V9).