building apis with nodejs on microsoft azure websites - redmond

Post on 10-Jun-2015

1.953 Views

Category:

Technology

1 Downloads

Preview:

Click to see full reader

DESCRIPTION

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

TRANSCRIPT

Building APIs with NodeJS on MicrosoftAzure Websites

Rick G. GaribayVP, Distinguished Engineer

Level: Intermediate

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: rick.garibay@neudesic.com | b-rigari@microsoft.com

The problem with long URLs…

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}

A terrible user experience at best.

But worse, a missed opportunity…

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

branding impression.

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}

http://neurl.it/pewUGm

Marketing CampaignsAdvertisements

PromotionsInternal Communication

A/B Testing

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.

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}

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"

}

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).

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

Hello Node

// 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

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

Client

Event Loop

Workers

IO

Callback

Response

Why Node?

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

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.

SHOW ME TEH CODEZImplementing the Create API

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

SHOW ME TEH CODEZImplementing the Redirect API

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

SHOW ME TEH CODEZImplementing the Hits API

Supported Publishing Methods

Supported Web Frameworks

Diagnostics & Monitoring

10 free sites. Multi-tenant. Daily quotas

100 free sites. Multi-tenant. Daily quotas

Unlimited. Dedicated VMs. + more

Unlimited. Dedicated VMs. No quotas

1shared

2shared

DEMODeploy Neurl.it to Azure with Git & Scale

Windows Azure Web Sites

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

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)

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

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/

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: rick.garibay@neudesic.com | b-rigari@microsoft.com

top related