Restful web services with nodejs

21
6000 Greenwood Plaza Blvd Suite 110 Greenwood Village, CO 80111 303.798.5458 www.aspenware.com RESTful Web Services with Node.js Michael Filbin [email protected]

description

Node.js (Node) , the brain child of Ryan Dahl, was released in 2009 when he worked for Joyent, Inc. Node is one of the most hyped technologies to arrive on the web development scene, though it is also one of the most misunderstood. So what is Node? Is it a programming language like Python, Java, or C++? Is it an application framework like Django, Rails, or Symphony? Is it maybe some type of middleware that can be plugged into existing web stacks like Memcached or RabbitMQ? Actually, it is none of the above. Node is simply a set of JavaScript language bindings to Google's powerful V8 engine. This begs the question: "what is a language binding and what is V8?" This presentation introduces Node from an architectural perspective by discussing its implementation followed by a practical demonstration of how to build an application using it through a real-world example. Michael Filbin of Aspenware explains how Ryan liberated JavaScript from the browser and brought the power of event-driven, non-blocked programming to every developer by using the world's most popular programming language.

Transcript of Restful web services with nodejs

Page 1: Restful web services with nodejs

6000 Greenwood Plaza BlvdSuite 110Greenwood Village, CO 80111303.798.5458

www.aspenware.com

RESTful Web Serviceswith Node.js Michael Filbin

[email protected]

Page 2: Restful web services with nodejs

RESTful Web Serviceswith Node.js

Brief Introduction to Node

Page 3: Restful web services with nodejs

What is Node.js?• A set of bindings to Google’s V8 JavaScript engine• Originally intended creating asynchronous TCP

servers• Other use cases:

• Web application frameworks• Language interpreters/preprocessors• Command-line interface utilities8

Brief Introduction to Node

https://github.com/joyent/node/wiki/Projects,-Applications,-and-Companies-Using-Node

RESTful Web Serviceswith Node.js

Page 4: Restful web services with nodejs

Node Architecture?• Standard Library is written in JavaScript• JS binding written in C/C++• Single-threaded• Event-driven• Non-blocking I/O• Modular dependency system• Allows for extension through C/C++ add-ons

RESTful Web Serviceswith Node.js

Brief Introduction to Node

Page 5: Restful web services with nodejs

What problems does it solve?• Concurrency• Latency• Complexity• Stability

RESTful Web Serviceswith Node.js

Brief Introduction to Node

Page 6: Restful web services with nodejs

Token Example:• Apache utilize multi-threading• Nginx utilizes asynchronous I/O

C10K problem – Dan Kegel

RESTful Web Serviceswith Node.js

Brief Introduction to Node

Page 7: Restful web services with nodejs

RESTful Web Serviceswith Node.js

Brief Introduction to Node

Page 8: Restful web services with nodejs

RESTful Web Serviceswith Node.js

Brief Introduction to Node

Page 9: Restful web services with nodejs

What is Asynchronous I/O?• Using an event loop

• Request is received• Non-IO operations return immediately• IO operations defer to system asych API

(epoll, kqueue, select)• IO interrupt received and callback is executed• Data returned to client

Brief Introduction to NodeRESTful Web Serviceswith Node.js

Page 10: Restful web services with nodejs

Brief Introduction to NodeRESTful Web Serviceswith Node.js

Page 11: Restful web services with nodejs

Paradigm change doesn’t have to be difficult…

Brief Introduction to NodeRESTful Web Serviceswith Node.js

Page 12: Restful web services with nodejs

1 $('#login').bind(’click', function(event){2 event.preventDefault();3 // Do something interesting4 });

RESTful Web Serviceswith Node.js

Brief Introduction to Node

Page 13: Restful web services with nodejs

RESTful Web Serviceswith Node.js

Brief Introduction to Node

Page 14: Restful web services with nodejs

RESTful Web Serviceswith Node.js

Shouting Match

Page 15: Restful web services with nodejs

Project Goals:• Single-page application• Server calls completely asynchronous• Utilize web sockets for real-time updates• RESTful service tier• More than just “Hello World”

RESTful Web Serviceswith Node.js

Shouting Match

Page 16: Restful web services with nodejs

Project Constraints:

Section Title Goes Here

• Crowd-source data• No way to authenticate users• Distributed development team• Simple deployment strategy• Very little time• Request throttling

RESTful Web Serviceswith Node.js

Page 17: Restful web services with nodejs

Technology Used:• Express application framework• Coffeescript• Jade markup templates• Less CSS preprocessor• “Twit” twitter client• “js-yaml” YAML parser• Mocha testing framwork• Chai DSL

RESTful Web Serviceswith Node.js

Shouting Match

Page 18: Restful web services with nodejs

RESTful Web Serviceswith Node.js

Conclusion

Page 19: Restful web services with nodejs

Summation & Thank you’s:

Conclusion

• Node is • not a fad…• not the answer to all your problems• gives you flexibility• fun to use

RESTful Web Serviceswith Node.js

Page 20: Restful web services with nodejs

More on Shouting Match:

Conclusion

Rob Clark Mike Filbin Adam Roderick

# 161009:30 – 10:30

A new Photoshop workflow

# 120410:45 – 11:45

RESTful Services with Node.js

# 113016:30 – 17:30

Application architecture using

Backbone and Node

RESTful Web Serviceswith Node.js

Page 21: Restful web services with nodejs

6000 Greenwood Plaza BlvdSuite 110Greenwood Village, CO 80111303.798.5458

www.aspenware.com

MichaelFilbinThis is where you can put your biographical info, buttry to keep it short otherwise it’ll push the signature too low.

Michael Filbin, Software Developer [email protected]