Mandarine.TS
Latest
Latest
  • Mandarine.TS
  • Getting started
    • Installing Deno Runtime
    • Setting up Environment
    • Quick Example
  • Concepts
  • Mandarine Project Structure
  • Mandarine CLI
    • CLI Reference
      • mandarine new
      • mandarine generate
      • mandarine run
  • Mandarine Core
    • Core Initialization
    • Mandarine.json
    • Dot env file
    • Properties
      • The @Value Decorator
    • Components
      • Controller
      • Middleware
      • Repository
      • Component
      • Service
      • Configuration
      • Manual Component
    • Dependency Injection
      • Accessing DI container
    • Resource Handlers
      • Resource Handler Registry
      • Resource Handler
      • Resource Resolver
  • Mandarine MVC
    • Web MVC
    • Controllers
      • Routes
        • Parameterized Routes
      • HTTP Handlers
      • @ResponseStatus
    • Custom Middleware
    • Session Middleware
    • CORS Middleware
    • Template Engine
      • @Render Decorator
      • Accessing data from template
    • Launching web-app
    • Serving Static Content
    • Multipart Form Data
  • Mandarine Security
    • Sessions
  • Mandarine Data
    • ORM
      • Data source
      • Models
      • Repositories
        • Interacting with data
        • Updating data
    • Mandarine Query Language
  • Resources
    • Changelog
  • Plugins
    • Optional
    • Promise Repeater
Powered by GitBook
On this page
  • Declaring routes
  • Usage

Was this helpful?

  1. Mandarine MVC
  2. Controllers

Routes

This page summarizes how to declare routes.

PreviousControllersNextParameterized Routes

Last updated 4 years ago

Was this helpful?

Please see before continuing.

Declaring routes

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

  • Route (string):

    • Required

    • Route of the endpoint

      • If the parent contains a base route, then they will be unified.

  • options ():

    • Optional

    • Contains:

      • responseStatus (): Default response status for endpoint.

Types of routes available

  • 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();

Request

# http://localhost:8080/hello-world
You have requested me. Hello World

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();
Mandarine MVC Controllers
controller
Mandarine.MandarineMVC.Routing.RoutingOptions
HttpStatusCode
See enum here