Wednesday, December 7, 2016

Underscore.js : The Best Developer Productivity Tool

If you are dealing with JavaScript/Json Objects or Arrays or Collections in your project, Underscore.js would be the best developer productivity tool. It has more than 80 + in-built utility functions to perform various operations on Javascript Objects.

At first glance, you may think that JQuery library and Underscore.js has similar functionality but JQuery library mainly concentrate on DOM manipulation whereas Underscore.js offers only utility functions to manipulate Javascript Objects.

Underscore.js offers more control on Javascript Object compare to JQuery
The file size of Underscore.js is less than 5.9 KB after compression and GZip.

You can download minimized Underscore.js from http://underscorejs.org/underscore-min.js
You can download complete utility functions from http://underscorejs.org/

Few popular utility functions

1.    pluck
var stooges = [{name: 'moe', age: 40}, {name: 'larry', age: 50}, {name: 'curly', age: 60}];
_.pluck(stooges, 'name');
Output : ["moe", "larry", "curly"]

2. find
var even = _.find([1, 2, 3, 4, 5, 6], function(num){ return num % 2 == 0; });
Output: 2

3. filter
var evens = _.filter([1, 2, 3, 4, 5, 6], function(num){ return num % 2 == 0; });
Output: [2, 4, 6]

4. min
var numbers = [10, 5, 100, 2, 1000];
_.min(numbers);
Output : 2

5. sortBy
var stooges = [{name: 'moe', age: 40}, {name: 'larry', age: 50}, {name: 'curly', age: 60}];
_.sortBy(stooges, 'name');
Output: [{name: 'curly', age: 60}, {name: 'larry', age: 50}, {name: 'moe', age: 40}];

6. countBy
_.countBy([1, 2, 3, 4, 5], function(num) {return num % 2 == 0 ? 'even': 'odd';});
Output : {odd: 3, even: 2}

Happy Coding :)

Sunday, December 4, 2016

Web API Token Based Authentication using OWIN, OAuth and Existing Login Table


REST API has become so popular with the rise of Mobile Application usage in the industry. Token Based Authentication is the best way to authenticate the user instead of cookie/session based authentication.

The following are the disadvantages of using server based session authentication
  1.  Using Sessions: On every user successfully authentication, server has to allocate session for the logged in user. So, It increases lot of overhead in the server 
  2.  Scalability: In-Proc sessions are stored in server memory , so it can not be easily scalable. 
  3. CORS: cookies don’t play well in case of multiple different domains. 

The following are the benefits of using token based authentication
  1.  Token based authentication is stateless. We are not storing any information about our user on the server or in a session. 
  2. Easy scalable to different servers 
  3. Easy to use in Mobile Application authentication No issues with CORS
You can download complete documentation from the URL : Download

You can download complete Visual Studio Source Code from the URL : Download

Happy Coding :)