0% found this document useful (0 votes)
229 views

Node - Js Hackathon

This document discusses building APIs with Node.js. It introduces Node.js and why it is useful for building APIs. It then covers installing Node.js, writing a simple "Hello World" program, debugging, testing, and using NPM. The document outlines steps for building an API, including documentation, performance tracking, authentication, usage tracking, and access control. It provides examples for implementing these steps and recommends libraries and tools. Finally, it advertises a demo and invites questions.

Uploaded by

Bob Corsaro
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
229 views

Node - Js Hackathon

This document discusses building APIs with Node.js. It introduces Node.js and why it is useful for building APIs. It then covers installing Node.js, writing a simple "Hello World" program, debugging, testing, and using NPM. The document outlines steps for building an API, including documentation, performance tracking, authentication, usage tracking, and access control. It provides examples for implementing these steps and recommends libraries and tools. Finally, it advertises a demo and invites questions.

Uploaded by

Bob Corsaro
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 19

Who are you?

bit.ly/rcorsaro @doki_pen github.com/dokipen works @ embed.ly

Agenda

Nodejs intro API Recipe Demo Questions

Node Intro

Why Node?

Async, fast enough for web programming Very active and talented community NPM makes code reuse a breeze Honestly, javascript isn't that bad

Installing Node
https://github.com/creationix/nvm

$ git clone git://github.com/creationx/nvm.git ~/nvm $ . ~/nvm/nvm.sh $ nvm install v0.8.6 $ nvm alias default 0.8.6

Hello World

var http = require('http'); http.createServer(function (request, response) { response.writeHead(200, {'Content-Type': 'text/plain'}); response.end('Hello World\n');}).listen(8124); console.log('Server running at http://127.0.0.1:8124/');

Debugging
https://github.com/dannycoates/node-inspector

Testing

https://github.com/visionmedia/should.js https://github.com/visionmedia/mocha https://github.com/visionmedia/supertest

NPM Everything
{

"name": "hackathon", "version": "0.0.1", "description": "My hackathon project", "main": "index.js", "scripts": { "test": "mocha" }, "dependencies": { "express": "3.0.0rc2", "mongodb": "0.0.1" }, "devDependencies": { "mocha": "*", "should": "*", "supertest": "*" }, "author": "Bob Corsaro", "license": "MIT" }

API Recipe

API Recipe (Yak Shaving)

Documentation Performance tracking Authentication Usage tracking Access Control (rate-limits, privileges) The actual service (and tests)

There are companies that do a lot of this for you for $. (mashery, apigee, 3scale)

Documentation
Remember wsdls? Contracts matter. Discovery matters.
https://github.com/wordnik/swagger-node-express https://github.com/dokipen/express-endpoint

Performance Tracking

http://graphite.wikidot.com/ https://github.com/etsy/statsd https://github.com/dokipen/connect-statsd

BSD, Solaris or SmartOS dtrace Linux =(

Authentication
If your API is public, you'll want to do the following.

Distribute keys (we have a django app for that) uuid4 is good Authenticate keys (we have a connect middleware for that) Support 2-legged OAuth. Version 1.0a is fine. Ability to block keys (we'll use it later)

Usage Tracking
Analytics vs. Rate Limiting Sync vs. Async

Access Control
Support JSONP Support CORS http://enable-cors.org/

Access-Control-Allow-Methods: GET, OPTIONS Access-Control-Allow-Origin: *

Demo

Questions

You might also like