# node:http

> How Elide supports Node's `http` and `https`: the HTTP/1.1 server and client and the HTTPS client; `https.createServer` and `node:http2` are unavailable.

`node:http` provides [Node's HTTP/1.1](https://nodejs.org/api/http.html) server and client; `node:https` provides the
client only. For a Fetch-style handler or HTTP/2, use [`Elide.serve`](https://elide.help/docs/api-globals-elide).

## Example

```js
// http.mjs
import { createServer } from "node:http";

const server = createServer((req, res) => {
  res.writeHead(200, { "content-type": "text/plain" });
  res.end(`${req.method} ${req.url}\n`);
});

server.listen(0, "127.0.0.1", async () => {
  const { port } = server.address();
  const response = await fetch(`http://127.0.0.1:${port}/hello`);
  console.log(response.status, response.headers.get("content-type"));
  console.log(await response.text());
  server.close();
});
```

`elide run http.mjs` prints:

```text
200 text/plain
GET /hello
```

## Differences from Node

- `https.createServer` throws `ERR_HTTPS_SERVER_UNSUPPORTED`; terminate TLS in front of `http.createServer`.
- `http.globalAgent` defaults to `keepAlive: true`, `maxSockets: Infinity`, and `maxFreeSockets: 256`.
- HTTPS certificate validation follows [fetch](https://elide.help/docs/api-whatwg-fetch).
- `node:http2` is unavailable.
- `--allow-net` and `--deny-net` apply under the [sandbox](https://elide.help/docs/sandbox).

## Samples

- [node:http server and client](https://elide.help/docs/code-samples#nodehttp-server-and-client)

<!-- api-reference:start f13d050c0262 -->
## Reference

**Status:** Partial · Not measured

### `http` exports

`Agent`, `ClientRequest`, `IncomingMessage`, `OutgoingMessage`, `Server`, `ServerResponse`, `createServer`, `get`, `globalAgent`, `maxHeaderSize`, `request`, `setMaxIdleHTTPParsers`, `validateHeaderName`, `validateHeaderValue`, 2 constants such as `METHODS`

### Not implemented

`CloseEvent`, `MessageEvent`, `WebSocket`, `setGlobalProxyFromEnv`.
<!-- api-reference:end -->
