axios-fauxy-interceptor
v0.1.3
Published
Records requests through [Axios](https://axios-http.com/) if they haven't been seen before or replays them otherwise.
Downloads
1
Readme
Records requests through Axios if they haven't been seen before or replays them otherwise.
To use, call create
to make an Axios instance with the fauxy interceptors installed:
const client = create({
fauxy: {
proxies: [
{
keyMaker: (req: FauxyRequest) => ({ path: req.url.pathname }),
libraryDir: "recordings",
},
],
},
});
async function ping(p0: number) {
const resp = await client.get("http://localhost:8080/ping");
console.log(p0, resp.data);
return resp.data;
}
const [first, second] = await Promise.all([ping(1), ping(2)]);
assert(first === second);
If we're running this server that returns an incremented number on each fetch of /ping
,
this will print the following:
1 pong 0
2 pong 0
It gets 0
for both ping fetches as the first request gets the initial value from the server and records it and the second request uses that recording.