Remult
Remult is a lightweight web application framework for Full-Stack TypeScript.
Define Entity classes
import { Entity, EntityBase, Field } from 'remult';
@Entity('Products', {
allowApiCrud: true
})
export class Product extends EntityBase {
@Field()
name: string = '';
@Field()
unitPrice: number = 0;
}
Find and manipulate data in front end code...
static increasePriceOfTofu(priceIncrease: number) {
const product = await remult.repo(Product).findFirst(p => p.name.isEqualTo('Tofu'));
product.unitPrice += priceIncrease;
await product.save();
}
...exactly the same way as in back end code
@BackendMethod({ allowed: Allow.authenticated })
static increasePriceOfTofu(priceIncrease: number, remult?: Remult) {
const product = await remult.repo(Product).findFirst(p => p.name.isEqualTo('Tofu'));
product.unitPrice += priceIncrease;
await product.save();
}
Secure the API with Fine-grained Authorization
@Entity<Article>('Articles', {
allowApiRead: true,
allowApiInsert: remult => remult.authenticated(),
allowApiUpdate: (remult, article) => article.author.id == remult.user.id
})
export class Article extends EntityBase {
@Field({ allowApiUpdate: false })
slug: string;
@Field({ allowApiUpdate: false })
author: Profile;
@Field()
content: string;
}
Remult handles the REST:
- Secured back-end API endpoints for Entities and back-end methods
- CRUD API requests (front end) / database commands (back end)
- Object-relational mapping
- Validations
- Caching
- Authorization
Installation
npm i remult
API Setup using Express
import * as express from 'express';
import { initExpress } from 'remult/server';
import 'entities';
let app = express();
initExpress(app);
app.listen(3002, () => console.log("Server started"));