Mokia
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),
});