Skip to content

πŸ’ An out of the box mock API server to help quickly create back-end prototype and data simulations.

License

Notifications You must be signed in to change notification settings

varHarrie/mokia

Folders and files

NameName
Last commit message
Last commit date

Latest commit

f1b8554 Β· Sep 9, 2021

History

5 Commits
Sep 9, 2021
Sep 8, 2021
Sep 8, 2021
Sep 8, 2021
Sep 8, 2021
Sep 9, 2021
Sep 8, 2021
Sep 8, 2021
Sep 8, 2021
Sep 9, 2021
Sep 8, 2021
Sep 8, 2021

Repository files navigation

logo

License Version Downloads Issues

Mokia

πŸ’ An out of the box mock API server to help quickly create back-end prototype and data simulations.

Documentation: δΈ­ζ–‡

Basic Usage

Create entry file (e.g. index.js):

// index.js
module.exports = {
  port: 3000,
  'GET /users'() {
    return this.list(() => ({ id: this.uuid(), name: this.fullName() }));
  },
  'GET /users/:id'(req) {
    return { id: req.params.id, name: this.fullName() };
  },
};

Start local http server:

npx mokia index.js --watch

Open browser and go to http://localhost:3000/users, you will get the response.

Advanced Usage

TypeScript Support and Class-style mock schema:

// index.ts

import mokia from 'mokia';

class User {
  @mokia.uuid()
  id: string;

  @mokia.fullName()
  name: string;

  constructor(id?: string) {
    if (id) this.id = id;
  }
}

class Article {
  @mokia.uuid()
  id: string;

  @mokia.generate(User)
  author: User;

  @mokia.passage()
  content: string;

  constructor(id?: string) {
    if (id) this.id = id;
  }
}

export default mokia.defineConfig({
  port: 3000,
  'GET /users': mokia.list(User),
  'GET /users/:id': (req) => new User(req.params.id),
  'GET /articles': mokia.list(Article),
  'GET /articles/:id': (req) => new Article(req.params.id),
});

License

MIT