https://github.com/segevfiner/fetch-light-my-request
fetch-mock wrapper over light-my-request
https://github.com/segevfiner/fetch-light-my-request
fetch fetch-mock http injection light-my-request nodejs
Last synced: 4 months ago
JSON representation
fetch-mock wrapper over light-my-request
- Host: GitHub
- URL: https://github.com/segevfiner/fetch-light-my-request
- Owner: segevfiner
- License: mit
- Created: 2025-05-10T15:48:16.000Z (9 months ago)
- Default Branch: main
- Last Pushed: 2025-08-01T12:25:14.000Z (6 months ago)
- Last Synced: 2025-09-07T17:26:31.141Z (5 months ago)
- Topics: fetch, fetch-mock, http, injection, light-my-request, nodejs
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/fetch-light-my-request
- Size: 257 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# fetch-light-my-request
[](https://github.com/segevfiner/fetch-light-my-request/actions/workflows/ci.yml)
[](https://segevfiner.github.io/fetch-light-my-request/)
[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](https://segevfiner.github.io/fetch-light-my-request/)
[fetch-mock]: https://www.wheresrhys.co.uk/fetch-mock/
[light-my-request]: https://www.npmjs.com/package/light-my-request
## Getting Started
```ts
const fetchMock = createFetchMockLightMyRequest((req, res) => {
res.end("Hello, World!");
});
const res = await fetchMock.fetchHandler("http://localhost/hello");
console.log(res.text());
```
Or with [Fastify]:
```ts
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.
[Fastify]: https://fastify.dev/
## License
MIT.