Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/varharrie/mokia

πŸ’ An out of the box mock API server to help quickly create back-end prototype and data simulations.
https://github.com/varharrie/mokia

api cli generator library mock nodejs server utility

Last synced: about 1 month ago
JSON representation

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

Awesome Lists containing this project

README

        



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: [δΈ­ζ–‡](https://varharrie.github.io/mokia/)

## Basic Usage

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

```javascript
// 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:

```bash
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:

```typescript
// 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](./LICENSE)