@helpscout/moxie
TypeScript icon, indicating that this package has built-in type declarations

0.0.1 • Public • Published

😘 Moxie

Build Status

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!

Dependencies (3)

Dev Dependencies (13)

Package Sidebar

Install

npm i @helpscout/moxie

Weekly Downloads

1

Version

0.0.1

License

MIT

Unpacked Size

14.1 kB

Total Files

19

Last publish

Collaborators

  • helpscout