Agent API

Agent API is low level interface for managing HTTP/1.1 Keep-Alive connection to the host.

It is the persist HTTP client to the same host and can be used as a connection pool. In most cases, fetch is enough for sending HTTP request but is useful to manage Keep-Alive connections.

// Copyright 2019 Yusuke Sakurai. All rights reserved. MIT license.
import { createAgent } from "https://servestjs.org/@v0.30.0/agent.ts";

async function main() {
  const agent = createAgent("https://servestjs.org");
  const res1 = await agent.send({ method: "GET", path: "/@/server.ts" });
  const res2 = await agent.send({ method: "GET", path: "/@/router.ts" });
  console.log(res1);
  console.log(res2);
}

main();