fetch-light-my-request
TypeScript icon, indicating that this package has built-in type declarations

0.1.4 • Public • Published

fetch-light-my-request

CI Docs

fetch-mock wrapper over light-my-request. This is useful to attach fetch based HTTP clients to a tested plain HTTP or Fastify server.

Documentation

Getting Started

const fetchMock = createFetchMockLightMyRequest((req, res) => {
  res.end("Hello, World!");
});

const res = await fetchMock.fetchHandler("http://localhost/hello");
console.log(res.text());

Or with Fastify:

import Fastify from "fastify";

const fastify = Fastify();
fastify.get("/hello", () => {
  return "Hello, World!";
});

const fetchMock = createFetchMockLightMyRequestFromFastify(fastify);
const res = await fetchMock.fetchHandler("http://localhost/hello");
console.log(res.text());

You can also use createFetchLightMyRequest or createFetchLightMyRequestFromFastify to directly return the resulting mock fetch function instead of the FetchMock instance.

License

MIT.

Package Sidebar

Install

npm i fetch-light-my-request

Weekly Downloads

2,273

Version

0.1.4

License

MIT

Unpacked Size

12.3 kB

Total Files

7

Last publish

Collaborators

  • segevfiner