@helpscout/moxie
v0.0.1
Published
Create client side mock API endpoints
Downloads
7
Maintainers
Readme
😘 Moxie
Create client side mock API endpoints
Table of Contents
Installation
npm install --save-dev @helpscout/moxie
Usage
import {createMoxie, createSchema, faker} from '@helpscout/moxie'
// Define your schemas
const UserSchema = createSchema({
id: faker.random.uuid(),
name: faker.name.firstName(),
})
// Create some initial state
const initialState = {
users: [
{
id: '123',
name: 'Randy Marsh',
},
],
}
// Create the mock database
const moxie = createMoxie(
'users',
{
users: UserSchema,
},
initialState,
)
// Make the "get" request!
moxie.get('users/123').then(response => {
console.log(response)
// {
// status: 200,
// statusText: 'OK',
// data: {
// id: '123',
// name: 'Randy Marsh',
// },
// headers: {
// 'Content-Type': 'application/json',
// },
// }
})
Thanks!
Thanks to lowdb for the database set up and to @jmauerhan for picking the 😘 emoji for Moxie!