Skip to content

liberatos278/next13-api-decorators

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published