1.0.1 • Published 3 years ago
kaito-http v1.0.1
kaito-http
typescript http framework built on top of express
installation
yarn add kaito-http
(or, with npm npm i --save kaito-http
)
why the name kaito?
this project is in memory of a close japanese friend of mine, called kaito
features
- ✍ built in schema + body validation support
- ⚡ ultra quick, built on top of express
- 💪 robust
- 💨 extremely easy to use, built with decorators
example
import { Request, Response } from "express";
@Controller("/")
class Home {
@Get("/")
async get(req: Request, res: Response) {
res.json({ success: true });
}
@Post("/")
@Schema<{ name: string }>(async (body) => typeof body?.name === "string")
async post(req: Request, res: Response) {
res.json(req.body);
}
}
const server = new Server(process.env.PORT || "8080", [new Home()]);
available decorators
methods
@Get
- for GET requests. You cannot use an@Schema
with this method@Post
– POST requests@Patch
– PATCH requests (usually mutations)@Put
– POST requests (usually insertions)@Delete
– POST requests (usually deletions)
utility
@Schema<ExpectedType>
- lets you check a request body to match a certain schema. if this function returnstrue
, req.body will be exactly as sent in the request. if the function returnsfalse
, the request will fail, and an error will be thrown and caught. if the function returns neither true nor false, the request will continue, and the result from the schema function will be the value ofreq.body
@Controller
- tellsReflect
that this class is a controller, and mounts your methods onto the express instance