1.0.5 • Published 4 years ago
@workali24/ignitic v1.0.5
Ignitic
Ignitic is an Open Source lightweight mini API Framework (based on Expressjs with Typescript).
Installation
Use the package manager npm or yarn to install Ignitic.
yarn add @workali24/ignitic
npm install --save @workali24/ignitic
For a better development install Express types (for routes methods in controllers)
yarn add --dev @types/express
npm install --save-dev @types/express
Usage
Server
import {Server, router} from '@workali24/ignitic';
import "path/to/controllers/index"
const server = new Server();
/* /api or whatever prefix you want */
server.use('/api', router)
server.listen(3000);
Database
import {Database, /* ... */} from '@workali24/ignitic';
Database.instance('databaseURL');
/* ... */
Controllers
import {Request, Response} from 'express';
import {Get} from '@workali24/ignitic';
export default class FooController {
@Get({ path: '/users', middlewares: []})
public index(req: Request, res: Response) {
return res.send('Foo Bar index');
}
}
Models
import {Model, ModelBase, Property} from '@workali24/ignitic';
@Model({name: 'Foo', collection: 'foos'})
class Foo extends ModelBase {
@Property({type: 'String', required: true})
foo: string;
@Property({type: 'String', required: true})
bar: string;
}
export default Foo;
import Foo from './Models/Foo'
/* ... */
const foo = new Foo.Model({foo: 'Foo', bar: 'Bar'})
await foo.save()
/* ... */
const foo = await Foo.Model.findOne({foo: 'Foo'})
Authentication (only JWT for the moment)
import {Authentication, /* ... */} from '@workali24/ignitic';
import User from './path/to/model/User'
Authentication.add('strategy', { model: User.Model });
/* ... */
import {Request, Response} from 'express';
import {Get, Auth} from '@workali24/ignitic';
export default class FooController {
@Get({ path: '/users', middlewares: []})
@Auth('strategy')
public index(req: Request, res: Response) {
return res.send('Foo Bar index');
}
}
Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.