1.1.1 • Published 1 year ago

next13-api-decorators v1.1.1

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

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

1.1.1

1 year ago

1.1.0

1 year ago

1.0.9-test-c

1 year ago

1.0.9-test-b

1 year ago

1.0.9-test

1 year ago

1.0.9-test-d

1 year ago

1.0.9

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago