fastify-plus
TypeScript icon, indicating that this package has built-in type declarations

0.0.2 • Public • Published

Install

npm

npm i fastify-plus

yarn

yarn add fastify-plus

Project Structure

- src
  - controllers
    - home.controller.ts
  - services
    - home.service.ts
  - dto
    - home.dto.ts
  - app.ts

Controller

in controller, create your route handler

// home.controller.ts
import { Controller, Get, RequestQuery } from 'fastify-plus';
import { HomeGetIndexRequest, HomeGetIndexResponse } from '../dto/home.dto';
 
@Controller()
export class HomeController {
  constructor(private readonly homeService: HomeService) {}
 
  @Get()
  index(
    @RequestQuery() homeGetIndexRequest: HomeGetIndexRequest,
  ): HomeGetIndexResponse {
    return this.homeService.getIndex(homeGetIndexRequest);
  }
}

Service

general, we write our application logic on services

import { Service } from 'fastify-plus';
import { HomeGetIndexRequest, HomeGetIndexResponse } from '../dto/home.dto';
 
@Service()
export class HomeService {
  getIndex(homeGetIndexRequest: HomeGetIndexRequest): HomeGetIndexResponse {
    return {
      name: homeGetIndexRequest.id,
    };
  }
}

App

import { FastifyPlusApplication } from 'fastify-plus';
 
async function bootstrap() {
  const app = new FastifyPlusApplication({
    appRootPath: __dirname,
  });
  await app.start(3000);
}
 
bootstrap();

now, you can access your api in http://127.0.0.1:3000/?id=2

todos

  • support swagger document
  • support property inject
  • get controller route param and generate schema

Readme

Keywords

none

Package Sidebar

Install

npm i fastify-plus

Weekly Downloads

20

Version

0.0.2

License

MIT

Unpacked Size

84.4 kB

Total Files

143

Last publish

Collaborators

  • metauro