Microsoft Cognitive service is an umbrella which has various APIs to help us intelligently.

Emotion API is one of them to determine the the expression or emotion in a image.

With the help of this Emotion service we can easily identify the emotion like happy, sad, fear,surprise etc. The best part of this API is that it detect all the faces in an image and provides the emotion collection object. Another good thing about this API is it is easy to use you just need to pass the image and rest other thing is handle by API itself.

Now, I am very sure you are curious to know more and want to implement it at your end. I am trying to share basic steps how you can use this in your project. just wanted to share that I am using MVC C# in my example .

In my example, I tried to upload an image and passing that image to API and according to API result showing the result. so Let’s begin with step by step

Most of the time when you write code for a web application you need to test it again and again. You have to run a whole flow of positive or negative test cases to check whether your application is working or not.

Now suppose your application have 20 pages and you need to traverse each individual page and may be perform some operation and on each change of your development you need to perform same thing.

sometimes, this thing will irritate you and you will skip testing which may be harmful because most of the time it happens when you skipped something you took a deep breath and at that moment your application crashed .

So , as a responsible developer we do not have to skip any test scenario but next question is how to reduce this effort which you feel boring sometime.

I can say we can reduce this effort by a installing a simple Firefox add-in which is absolutely free. The add in “Selenium add in”

once you have installed this you will find the selenium icon near by search bar as shown below

when you click this icon you will get a selenium interface as shown below

The basic concept of this tool is what ever you will run in browser it has capability of recording those steps so it is just play button and pause button game, no rocket science. You can easily run and use this.

I am sure it will reduce your testing effort and when when selenium ide will play your test cases you can take a deep breath and enjoy your coffee and snacks.

What we are planning here to create a page with menus and in this page we will call sammy.js on menu to call responsive URL to show states list ,particular state according to id and default page . as shown in below figure

Step 1:- Add “Sammy.js” in the project using Nuget package manager as shown in below figure

Step 2:- Once the Sammy.Js added in your project you will find the Js in your project’s script folder

Step 3:-

Add sammy js reference in the project

1: <script src="~/Scripts/jquery-2.1.0.min.js"></script>

2: <script src="~/Scripts/sammy-0.7.4.min.js"></script>

Step 4:-

Now below screen shot show the html which is designed to achieve our task

Step 5:- Now when Home menu link click by end user we will show default page which in Index page in our case and its URL will be

$.sammy(‘#main’,function() {}).run(); this is the basic function to invoke sammy.js

Step 8:- Now to which url we need to entertain by which method like get, put, Post, delete. We need to define our functionality according to our need in current example we have used get function.

this.get(‘#/’,function (context){});

The meaning of above line is when ever a request (default) invoke by end user just execute function as defined. in the function there is context parameter . Which help in accessing method type (get/post) , parameters

Step 9:- Now when you run and click on States link you will get following screen

Step 10:- you can test it further I have added list of states also with dynamic url so when you click on MP, RJ, MH etc in above list you will get a new URL according to our need

I hope this example will help you to create your own SPA application.

I defiantly say here “Sammy.js” rock. I like this script hope you will also.

So here we will understand this by an example. I am pretty much sure you all are comfortable with server side code so here in current example we using client side code to consume web API.

In current example I have created a Web API with name “MyState” . The basic functionality of this Web API is to provide list of all the State with default get method and provide specific state according to provided id.

Now to consume this Web API in our project we have added a view with following Java script

in below screen we have used a “get” JQUERY function and as we know the API URL we wrote that and once the response from API returned we concatenated the response array with <li> tag and show as a innerHTML of stateName div as shown in below fig

Now when we run this program on index.cshtml we got following response

In current example we have used “GET” method we can also consume post operation for INSERT/UPDATE/Delete

We have discussed what is Web API. Now in this article we will see how to create web API. So with out wasting much time lets start visual studio (In my case I am running VS 2013 web express).

So in my example I am creating a web API project for Friends. this API should return either all the friends or specific friend according to Id so lets start.

Step 1: Create a new web project when you click on web project you will get following option. Select Web API option as shown in below screen shot.

You will get default project as below with defined folder structure

The main point here is to remember Model class should come in model folder & Controller class should come in controller folder

Step 2:- Once you click on Web API option project will open. Now Create a model (a simple class) with name Friend. this model class have basic friend’s property like his firstName, LastName,Id etc. as shown in below fig

Step 3:- Now create a Friend controller so for this just add new item which is controller as shown in below fig

In the above option I have selected Web API 2 controller Empty template

things to remember here the name of controller class will be use later on in your API URL so select the name properly and the controller class name should followed by controller.

In my case I have created controller with following name =”FriendController.cs”. So now your project structure is as shown below

Step 4:- Now remember all the coding part need to be done here . I am creating two method here one method with name “GetAllFriends” and “GetFriendById”.

So as name suggest one will return list of all friends and one will return particular friend for a given id. If you see below instead of fetching data from database I have created a array of friends as shown.

Now in above fig you saw two method with different return type. Now concentrate on GetFriendByID It’s return type is HttpActionResult. so if you see below in that particular method the return type is OK which means status code 200. It means http response will be return in this method.

Now another interesting part is you can add different attribute with method like HTTPGET, HTTPPOST,HTTPDELETE etc Just see in below screen shot as shown below.

Now another interesting point is what if you want two attribute on same method then you can use below option which shown “AcceptVerbs”

Step 5:- Now our most part is done now you need to access web API but before accessing web API you need to check route and if something is missing their then you need to modify WebAPI config which you will get in App_Start function. In my case I have added API/{controller}/{action}/{id} which was not exist earlier. as shown in below fig

HTTP is simple way to connect broad range of clients, including browser, mobile & desktop application. To achieve above broad range a new framework is introduce on top of .NET framework which is called ASP.NET web API.

With ASP.NET Web API you can call simple RESTFul service. You can perform various GET, PUT, POST, DELETE operation using Web API.

Web API is enable to service data request from client in both (JASON /XML) format according to client need.

Web API introduced with ASP.NET MVC framework in later stage. If you are familiar with MVC application then you will think it is same.

For example you want to get list of all the customers then a URL may be like below