Skip to content

⚔️ Declarative NodeJS web framework with REST API route auto-generation, DI, and decorators, build on top of Fastify and TypeScript.

License

Notifications You must be signed in to change notification settings

FastifyResty/fastify-resty

Repository files navigation

Build Workflow codecov Known Vulnerabilities Depfu

GitHub license Maintenance lerna

Modern and declarative REST API framework for superfast and oversimplification backend development, build on top of Fastify and TypeScript.


If you find this useful, please don't forget to star ⭐  the repo, as this will help to promote the project.


Benefits 🎯

  • Zero configuration - Generates RESTful API routes for your data out the box
  • JSON Schema validation - Build JSON Schemas to validate and speedup your requests and replies
  • Highly customizable - provides a lot of possible configurations for your application
  • Purely TypeScript - Written in TypeScript and comes with all the required typings
  • Declarative interface - Uses decorators for routes and models definitions
  • Fastify compatible - Built with Fastify and supports all its features and plugins
  • Built-in DI - Provides simple Dependency Injection interface to bind your entries

Install 📌

Core module

$ npm install @fastify-resty/core fastify

TypeORM connector

$ npm install @fastify-resty/typeorm typeorm

Usage 🚀

TypeORM Entity (author.entity.ts):
import { Entity, Column, PrimaryGeneratedColumn, CreateDateColumn } from 'typeorm';

@Entity()
export default class Author {
  @PrimaryGeneratedColumn()
  id: number;

  @Column()
  firstname: string;

  @Column()
  lastname: string;

  @CreateDateColumn()
  created_at: Date;
}
Entity controller (author.controller.ts):
import { EntityController } from '@fastify-resty/core';
import AuthorEntity from './author.entity';

@EntityController(AuthorEntity, '/authors')
export default class AuthorController {}
Bootstrap (app.ts):
import fastify from 'fastify';
import { createConnection } from 'typeorm';
import { bootstrap } from '@fastify-resty/core';
import typeorm from '@fastify-resty/typeorm';
import AuthorController from './author.controller';

async function main() {
  const app = fastify();
  const connection = await createConnection();

  app.register(typeorm, { connection });
  app.register(bootstrap, { controllers: [AuthorController] });

  app.listen(8080, (err, address) => {
    console.log(app.printRoutes());
  });
}

main();
Generated routes:
└── /
    └── users (DELETE|GET|PATCH|POST|PUT)
        └── / (DELETE|GET|PATCH|POST|PUT)
            └── :id (DELETE)
                :id (GET)
                :id (PATCH)
                :id (PUT)

Documentation 📚

Packages 📦

Examples 🔬

Issues and contributions 📝

Contributors are welcome, please fork and send pull requests! If you find a bug or have any ideas on how to improve this project please submit an issue.

License

MIT License

Icons made by Eucalyp from www.flaticon.com

About

⚔️ Declarative NodeJS web framework with REST API route auto-generation, DI, and decorators, build on top of Fastify and TypeScript.

Topics

Resources

License

Stars

Watchers

Forks