Skip to content

varHarrie/mokia

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

5 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

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