next13-api-decorators
TypeScript icon, indicating that this package has built-in type declarations

1.1.1 • Public • Published

Next.js API decorators

Next.js MIT License

A library that will increase the clarity of API paths in your Next.js project. It is inspired by the well-known Nest.js framework, so it uses a number of decorators, for example to define the endpoints themselves and offers compatibility with the new app folder system that has appeared in new versions of Next.js.. This package is based on an existing package that is not compatible with the new version of Next.js next-api-decorators.

Installation

Installation with npm or yarn.

  npm install next13-api-decorators
  yarn add next13-api-decorators

Usage

import {
  ApiRouteHandler,
  ValidationPipe,
  HttpStatus,
  Get,
  Post,
  Delete,
  Query,
  Body,
  Param,
} from "next13-api-decorators"
import { CreateUserDto } from "../user.dto"

class UserController extends ApiRouteHandler {
  @Get()
  getUser(@Query("name") name: string) {
    return db.users.get(name)
  }

  @Post()
  createUser(@Body(ValidationPipe) body: CreateUserDto) {
    const newUser = db.users.create(body)
    return {
      data: newUser,
      statusCode: 200,
    }
  }

  @Delete("/:userId")
  @HttpStatus(204)
  deleteUser(@Param("userId") userId: string) {
    db.user.delete(userId)
  }
}

export const { GET, POST, DELETE } = UserController.build()

Authors

Package Sidebar

Install

npm i next13-api-decorators

Weekly Downloads

7

Version

1.1.1

License

MIT

Unpacked Size

83.5 kB

Total Files

6

Last publish

Collaborators

  • liberatos278