Routes

This page summarizes how to declare routes.

Please see Mandarine MVC Controllers before continuing.

Declaring routes

Routes are declared by using specific decorators, these decorators have two parameters:

Types of routes available

See enum here

  • GET

  • POST

  • PUT

  • HEAD

  • DELETE

  • OPTIONS

  • PATCH

Usage

Syntax:

import { GET, POST, PUT, HEAD, DELETE, OPTIONS, PATCH, CONTROLLER, MandarineCore } from "https://deno.land/x/mandarinets/mod.ts";

@Controller()
export class MyController {
    
    @GET('/hello-world')
    public httpHandler() {
        return "You have requested me. Hello World";
    }
    
}

new MandarineCore().MVC().run();

Note that in the example above we are only using GET, but all the route types listed above are available to be used. For example, if you would like to use POST instead of GET, it would be:

import { GET, POST, PUT, HEAD, DELETE, OPTIONS, PATCH, CONTROLLER, MandarineCore } from "https://deno.land/x/mandarinets/mod.ts";

@Controller()
export class MyController {
    ...
    @POST('/hello-world')
    ...
}

new MandarineCore().MVC().run();

Last updated