Skip to content

Instantly share code, notes, and snippets.

@scottgamer
Last active March 31, 2022 14:12
Show Gist options
  • Select an option

  • Save scottgamer/7da120cca3809092f8a0cbfde04c5343 to your computer and use it in GitHub Desktop.

Select an option

Save scottgamer/7da120cca3809092f8a0cbfde04c5343 to your computer and use it in GitHub Desktop.
msw initial handler
import { rest } from "msw";
import CONSTANTS from "../constants";
function getPosts() {
return rest.get(`${CONSTANTS.API_URL}/posts`, (req, res, ctx) => {
return res(
ctx.status(200),
ctx.json([
{
userId: 1,
id: 1,
title: "Post 1 title",
body: "Post 1 body",
},
{
userId: 1,
id: 2,
title: "Post 2 title",
body: "Post 2 body",
},
])
);
});
}
export const handlers = [getPosts()];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment