Interacting with the Web - Node JS
Outline
- Using Node as a web client
- Building a web server
- 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