3 IoT.js provides HTTP to support HTTP server and client enabling users to receive/send HTTP request easily.
6 ### http.createServer(requestListener)
7 * `requestListener: Function`
8 * Return: `http.Server` instance
11 ### http.request(options[, callback])
13 * `callback: Function`
14 * Return: `http.ClientRequest` instance
16 ### http.get(options[, callback])
18 * `callback: Function`
19 * Return: `http.ClientRequest` instance
21 Same as http.request except that `http.get` automatically call `req.end()` at the end.
29 * `request: http.IncomingMessage` instance.
30 * `response: http.ServerResponse` instance.
31 After request header is parsed, this event will be fired.
34 This event is emitted when new TCP connection is established.
37 This event is emitted when server is closed.
41 #### listen(port[, hostname][, backlog][, callback])
45 * `callback: Function`
47 Wait for new TCP connection with specified port and hostname. If no hostname is provided, server accepts any IP address.
48 `backlog` is maximum pending connections. Default backlog length is 511.
49 `callback` will be called when server has been bound.
51 #### close([callback])
52 * `callback: Function`
54 Stop accepting new connection to this server. However, the existing connections are preserved. When server is finally closed after all connections are closed, a callback is called.
56 #### setTimeout(ms, cb)
61 Registers cb for 'timeout' event and sets socket's timeout value to ms. This event will be triggered by the underlying socket's 'timeout' event.
63 If cb is not provided, the socket will be destroyed automatically after timeout.
64 If you provide cb, you should handle the socket's timeout.
66 Default timeout for server is 2 minutes.
70 Server's timeout value. Default value is 2 minutes.
73 ## Class: http.ClientRequest
77 * `response: http.IncomingMessage` instance
79 This event is emitted when server's response header is parsed. ` http.IncomingMessage` object is passed as argument to handler.
83 * `Net.socket` instance
85 This event is emitted when a socket is assigned to this request. `Net.socket` object is passed as argument to handler.
87 After response header is parsed, this event will be fired.
91 #### write(data[, callback])
92 * `data: Buffer|String`
93 * `callback: Function`
95 Sends `data` as a request body. `callback` will be called when data is flushed.
98 #### end([data][, callback])
99 * `data: Buffer|String`
100 * `callback: Function`
102 Finishes sending the request.
104 If `data` is provided, it sends `data` first, and finishes.
106 If `callback` is specified, it is called when the request stream is finished.
110 #### setTimeout(ms, cb)
115 Registers cb for 'timeout' event and set socket's timeout value to ms. This event will be triggered by the underlying socket's 'timeout' event.
117 If cb is not provided, the socket will be destroyed automatically after timeout.
118 If you provides cb, you should handle the socket's timeout.
121 ## Class: http.ServerResponse
124 This event is fired when no more data to be sent.
127 When underlying connection is closed, 'close' event is emitted.
130 This event is emitted when the response has been sent. It does not guarantee that client has received data yet.
133 #### writeHead(statusCode[, statusMessage][, headers])
134 * `statusCode: Number`
135 * `statusMessage: String`
138 Sets response's header. `headers` is a map between field and value in header.
140 #### setHeader(name, value)
144 Sets response's header field(`name`) to `value`. If the field exists, it overwrites the existing value.
149 Returns `name` field of response's header
151 #### removeHeader(name)
154 Removes `name` field from response's header
156 #### write(data[, callback])
157 * `data: Buffer|String`
158 * `callback: Function`
160 Sends `data` as a response body. `callback` will be called when data is flushed.
162 #### end([data][, callback])
163 * `data: Buffer|String`
164 * `callback: Function`
166 Finishes sending the response.
168 If `data` is provided, it sends `data` first, and finishes.
170 If `callback` is specified, it is called when the response stream is finished.
172 #### setTimeout(ms, cb)
177 Registers cb for 'timeout' event and set socket's timeout value to ms. This event will be triggered by the underlying socket's 'timeout' event.
181 ## Class: http.IncomingMessage
183 http.IncomingMessage inherits [`Stream.readable`](IoT.js-API-Stream.md)
187 This event is fired when no more data to be received.
190 When underlying connection is closed, 'close' event is emitted.
193 #### setTimeout(ms, cb)
198 Registers cb for 'timeout' event set socket's timeout value to ms. This event will be triggered by the underlying socket's 'timeout' event.
207 Requests method as `String`
210 Requests URL as `String`
213 HTTP response status code as `Number` of 3-digit.
216 HTTP response status message as `String`