0.0.1 • Published 6 months ago

@bjorkhaug/smethod v0.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

smethod

A simple route decorators for Deno to populate class methods with metadata for routing.

Usage

import {
  Connect,
  Delete,
  Get,
  Head,
  Options,
  Patch,
  Post,
  Put,
  Trace,
} from './mod.ts'

You can use these decorators to annotate your class methods:

class MyController {
  @Get('/')
  async home() {
    // Your code here
  }

  @Post('/create')
  async create() {
    // Your code here
  }

  // Other methods...
}

Each decorator corresponds to an HTTP method. The argument to the decorator is the route path.

You can get the routes defined in a class using the getRoutes method from the Methods class:

import { Methods } from './methods.ts'

const routes = Methods.getRoutes(MyController)

This will return an array of route definitions, each with a route, method, and handler property.