Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/helpscout/moxie

😘 Moxie: Create client side mock API endpoints
https://github.com/helpscout/moxie

api client-side generator javascript mock open-source

Last synced: about 2 months ago
JSON representation

😘 Moxie: Create client side mock API endpoints

Awesome Lists containing this project

README

        

# 😘 Moxie

[![Build Status](https://travis-ci.org/helpscout/moxie.svg?branch=master)](https://travis-ci.org/helpscout/moxie)

> Create client side mock API endpoints

## Table of Contents

- [Installation](#installation)
- [Usage](#usage)
- [Thanks!](#thanks)

## Installation

```
npm install --save-dev @helpscout/moxie
```

## Usage

```js
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](https://github.com/lowdb/lowdb) for the database set up and to [@jmauerhan](https://github.com/jmauerhan) for picking the 😘 emoji for Moxie!