Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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 3 hours ago
JSON representation
π An out of the box mock API server to help quickly create back-end prototype and data simulations.
- Host: GitHub
- URL: https://github.com/varharrie/mokia
- Owner: varHarrie
- License: mit
- Created: 2018-12-06T16:14:11.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2022-12-10T16:36:51.000Z (almost 2 years ago)
- Last Synced: 2024-11-14T18:55:16.410Z (5 days ago)
- Topics: api, cli, generator, library, mock, nodejs, server, utility
- Language: TypeScript
- Homepage: https://varharrie.github.io/mokia/
- Size: 3.24 MB
- Stars: 113
- Watchers: 3
- Forks: 7
- Open Issues: 12
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# 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.tsimport 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)