building apis with nodejs on microsoft azure websites - redmond

45
Building APIs with NodeJS on Microsoft Azure Websites Rick G. Garibay VP, Distinguished Engineer Level: Intermediate

Upload: rick-g-garibay

Post on 10-Jun-2015

1.953 views

Category:

Technology


1 download

DESCRIPTION

Visual Studio Live Redmond 2014 - code https://github.com/rickggaribay/IoT

TRANSCRIPT

Page 1: Building APIs with NodeJS on Microsoft Azure Websites - Redmond

Building APIs with NodeJS on MicrosoftAzure Websites

Rick G. GaribayVP, Distinguished Engineer

Level: Intermediate

Page 2: Building APIs with NodeJS on Microsoft Azure Websites - Redmond

About Me• VP, Distinguished Engineer leading the Development

Platform Group at Neudesic• Working on IoT, Intelligent Transportation and Hospitality

& Gaming• Microsoft MVP, Microsoft Azure• Co-Author, “Windows Server AppFabric Cookbook” by

Packt Pub.• Chairman, Co-Founder Phoenix Connected Systems User

Group (PCSUG.org)• twitter: @rickggaribay• blog: http://rickgaribay.net• email: [email protected] | [email protected]

Page 3: Building APIs with NodeJS on Microsoft Azure Websites - Redmond

The problem with long URLs…

Page 4: Building APIs with NodeJS on Microsoft Azure Websites - Redmond

http://mysadsharepointsite/not/rest/ful/Foo.aspx?RootFolder=%2Fpractice%2FConnected%5FSystems%2FDocuments%2F5%2E%20Training%20Resources&FolderCTID=0x0120006C1E110A70E85644A26E

2C21A71B0D82&View={8F82FE4D-9398-4892-B6E6-C2D9C2AB2BE8}

Page 5: Building APIs with NodeJS on Microsoft Azure Websites - Redmond

A terrible user experience at best.

Page 6: Building APIs with NodeJS on Microsoft Azure Websites - Redmond

But worse, a missed opportunity…

Page 7: Building APIs with NodeJS on Microsoft Azure Websites - Redmond

Every URL you send a customer, partner,prospect is an opportunity to make a

branding impression.

Page 8: Building APIs with NodeJS on Microsoft Azure Websites - Redmond

http://mysadsharepointsite/not/rest/ful/Foo.aspx?RootFolder=%2Fpractice%2FConnected%5FSystems%2FDocuments%2F5%2E%20Training%20Resources&FolderCTID=0x0120006C1E110A70E85644A26E

2C21A71B0D82&View={8F82FE4D-9398-4892-B6E6-C2D9C2AB2BE8}

Page 9: Building APIs with NodeJS on Microsoft Azure Websites - Redmond

http://neurl.it/pewUGm

Page 10: Building APIs with NodeJS on Microsoft Azure Websites - Redmond

Marketing CampaignsAdvertisements

PromotionsInternal Communication

A/B Testing

Page 11: Building APIs with NodeJS on Microsoft Azure Websites - Redmond

neurl.it v0.1

• Shorten/Create– When I submit a long, ugly URL to the create API, I

should get back a neurl.• Redirect

– When I submit a neurl to the submit API, myrequest should be automatically redirected.

• Hits– When I submit a neurl to the hits API, I should get

back the number of hits/redirects for that neurl.

Page 12: Building APIs with NodeJS on Microsoft Azure Websites - Redmond

http://mysadsharepointsite/not/rest/ful/Foo.aspx?RootFolder=%2Fpractice%2FConnected%5FSystems%2FDocuments%2F5%2E%20Training%20Resources&FolderCTID=0x0120006C1E110A70E85644A26E

2C21A71B0D82&View={8F82FE4D-9398-4892-B6E6-C2D9C2AB2BE8}

Page 13: Building APIs with NodeJS on Microsoft Azure Websites - Redmond
Page 14: Building APIs with NodeJS on Microsoft Azure Websites - Redmond
Page 15: Building APIs with NodeJS on Microsoft Azure Websites - Redmond
Page 16: Building APIs with NodeJS on Microsoft Azure Websites - Redmond

POST http://neurl.it/create HTTP/1.1User-Agent: FiddlerHost: neurl.itContent-Type: application/json; charset=utf-8Content-Length: 36

{"Url" : "http://rickgaribay.net"}

HTTP/1.1 200 OKX-Powered-By: ExpressContent-Type: application/json; charset=utf-8Content-Length: 57Date: Fri, 08 Mar 2013 05:00:21 GMTConnection: keep-alive

{"http://neurl.it/pewUGm"

}

Page 17: Building APIs with NodeJS on Microsoft Azure Websites - Redmond

What is NodeJS?

• Server-side scripting framework based on theGoogle V8 engine accessible via JavaScript.

• Asynchronous by nature, making it veryperformant.

• Growing community and industry support,including libraries (modules).

Page 18: Building APIs with NodeJS on Microsoft Azure Websites - Redmond

// Say Hello via Consoleconsole.log("Hello World");

Hello Node

Page 19: Building APIs with NodeJS on Microsoft Azure Websites - Redmond

// Load the http module to create an http server.var http = require('http');

// Configure our HTTP server to respond with Hello World to allrequests.var server = http.createServer(function (request, response) {response.writeHead(200, {"Content-Type": "text/plain"});response.end("Hello World\n");

});

// Listen on port 8000server.listen(8000);

// Put a friendly message on the terminalconsole.log("Server running at http://127.0.0.1:8000/");

Hello Node

Page 20: Building APIs with NodeJS on Microsoft Azure Websites - Redmond

NodeJS Fundamentals

• Node Package Manager (NPM) – Package managerfor downloading and referencing thousands ofNodeJS modules.

• Package.json – Captures information aboutmodules (including your project/module) anddependencies.

• Server.js – Typical entry point to a NodeJSapplication but any .js will do.

• Running NodeJS apps is as simple as this:> node server.js

Page 21: Building APIs with NodeJS on Microsoft Azure Websites - Redmond

Client

Event Loop

Workers

IO

Callback

Response

Page 22: Building APIs with NodeJS on Microsoft Azure Websites - Redmond

Why Node?

• My goal is not to convince you to use NodeJSover ASP.NET, Web API, WCF or any otherback-end framework.

Page 23: Building APIs with NodeJS on Microsoft Azure Websites - Redmond

Why Node?

• Rather, I want to show you a practical exampleof what you can do with NodeJS.

• Alternate implementations, either in NodeJSor other platforms, frameworks and languagesis left as an exercise to the reader.

Page 24: Building APIs with NodeJS on Microsoft Azure Websites - Redmond

SHOW ME TEH CODEZImplementing the Create API

Page 25: Building APIs with NodeJS on Microsoft Azure Websites - Redmond
Page 26: Building APIs with NodeJS on Microsoft Azure Websites - Redmond
Page 27: Building APIs with NodeJS on Microsoft Azure Websites - Redmond

GET http://neurl.it/pewUGm HTTP/1.1User-Agent: FiddlerHost: neurl.itContent-Type: application/json; charset=utf-8Content-Length: 0

HTTP/1.1 302 Moved TemporarilyX-Powered-By: ExpressLocation: http://rickgaribay.netVary: AcceptContent-Type: text/plainContent-Length: 56Date: Fri, 08 Mar 2013 05:16:45 GMTConnection: keep-alive

Moved Temporarily. Redirecting to http://rickgaribay.net

Page 28: Building APIs with NodeJS on Microsoft Azure Websites - Redmond

SHOW ME TEH CODEZImplementing the Redirect API

Page 29: Building APIs with NodeJS on Microsoft Azure Websites - Redmond

GET http://neurl.it/pewUGm/hits HTTP/1.1User-Agent: FiddlerHost: neurl.itContent-Type: application/json; charset=utf-8Content-Length: 0

HTTP/1.1 200 OKX-Powered-By: ExpressContent-Type: text/html; charset=utf-8Content-Length: 2Date: Fri, 08 Mar 2013 05:21:37 GMTConnection: keep-alive

42

Page 30: Building APIs with NodeJS on Microsoft Azure Websites - Redmond

SHOW ME TEH CODEZImplementing the Hits API

Page 31: Building APIs with NodeJS on Microsoft Azure Websites - Redmond
Page 32: Building APIs with NodeJS on Microsoft Azure Websites - Redmond
Page 33: Building APIs with NodeJS on Microsoft Azure Websites - Redmond

Supported Publishing Methods

Page 34: Building APIs with NodeJS on Microsoft Azure Websites - Redmond

Supported Web Frameworks

Page 35: Building APIs with NodeJS on Microsoft Azure Websites - Redmond

Diagnostics & Monitoring

Page 36: Building APIs with NodeJS on Microsoft Azure Websites - Redmond

10 free sites. Multi-tenant. Daily quotas

100 free sites. Multi-tenant. Daily quotas

Unlimited. Dedicated VMs. + more

Unlimited. Dedicated VMs. No quotas

Page 37: Building APIs with NodeJS on Microsoft Azure Websites - Redmond

1shared

Page 38: Building APIs with NodeJS on Microsoft Azure Websites - Redmond

2shared

Page 39: Building APIs with NodeJS on Microsoft Azure Websites - Redmond

DEMODeploy Neurl.it to Azure with Git & Scale

Page 40: Building APIs with NodeJS on Microsoft Azure Websites - Redmond

Windows Azure Web Sites

Page 41: Building APIs with NodeJS on Microsoft Azure Websites - Redmond

Start Simple

Get started with 10 free web sites

Create new sites in seconds

Easily manage and scale your sites

Automatic load balancing and sharedstorage across instances

Scale out or up to reserved instances forimproved performance and scale

Page 42: Building APIs with NodeJS on Microsoft Azure Websites - Redmond

Code Smart

Use ASP.NET, ASP, PHP, or NodeJS

SQL Azure or MySQL databases

Start with open source apps and frameworks

Develop with VS and WebMatrix

Supports any Web development tool on anyplatform (Windows, OSX, Linux)

Page 43: Building APIs with NodeJS on Microsoft Azure Websites - Redmond

Go Live

Rapid deployment for quick iteration

Integrated source control with TeamFoundation Server (TFS) and Git

Built-in monitoring of perf and usage data

Quick access to request logs, failed requestsdiagnostics and diagnostics

Page 44: Building APIs with NodeJS on Microsoft Azure Websites - Redmond

Resources• Building Hypermedia APIs with HTML5 and Node by Mike

Amudsen• Express http://expressjs.com/• Mocha http://visionmedia.github.com/mocha/• Should https://github.com/lukebayes/node-should• SuperTest https://github.com/visionmedia/supertest• MongoDb http://www.mongodb.org/• Mongoose https://github.com/LearnBoost/mongoose• Fiddler http://www.fiddler2.com/fiddler2/• Microsoft Azure: http://Azure.com• Configuring Domain Names on Azure Websites

http://bit.ly/1pvOclYAzure CLI http://azure.microsoft.com/en-us/documentation/articles/xplat-cli/

Page 45: Building APIs with NodeJS on Microsoft Azure Websites - Redmond

About Me• VP, Distinguished Engineer leading the Development

Platform Group at Neudesic• Working on IoT, Intelligent Transportation and Hospitality

& Gaming• Microsoft MVP, Microsoft Azure• Co-Author, “Windows Server AppFabric Cookbook” by

Packt Pub.• Chairman, Co-Founder Phoenix Connected Systems User

Group (PCSUG.org)• twitter: @rickggaribay• blog: http://rickgaribay.net• email: [email protected] | [email protected]