Sunday, February 23, 2014

Interacting with the Web - Node JS

Outline

  1. Using Node as a web client
  2. Building a web server
  3. Real-time integration using Socket.IO

Making web requests in Node

  • “options” can be one of the following:
    • A URL string
    • object specifying values for host, port, method, path, headers, auth, etc.
  • The returned ClientRequest can be written/piped to for POST requests
  • The ClientResponse object is provided via either callback (shown above) or as a “response” event on the request object.
  • http.get() available as a simplified interface for GET requests.

Building a Web Server in Node


  • Each request is provided via either callback (shown above) or as a “request” event on the server object
  • The ServerRequest can be read from (or piped) for POST uploads
  • The ServerResponse can be piped to when returning stream-oriented data in a response
  • SSL support is provided by a similar https.createServer()


No comments:

Post a Comment