8000 GitHub - Krytius/mvc-deno
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Krytius/mvc-deno

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Deno MVC API Simple

GitHub release (Deno)

Example Start Proccess

main.ts

import {opine} from "https://deno.land/x/opine@0.26.0/mod.ts";
import {Mvc} from "https://deno.land/x/mvc@v0.0.10/mod.ts";

let app = opine();
let mvc = new Mvc(app, Deno.cwd());
await mvc.start(3000);

Automatically creates routes for everything inside the controller folder. Example:

.
├── controller
│   ├── game.ts
├── main.ts

game.ts

Controller Structure:

import {ControllerInterface} from "https://deno.land/x/mvc@v0.0.10/mod.ts";

export class Game implements ControllerInterface {

    middleware(req: any, res: any, next: any) {
        next();
    };

    /**
     * METHOD GET
     * @param req
     * @param res
     */
    get(req: any, res: any) {
        res.send(req.url);
    }

    /**
     * METHOD GET /:id
     * @param req
     * @param res
     */
    getItem(req: any, res: any) {
        throw new Error("Method not implemented.");
    }

    /**
     * METHOD POST
     * @param req
     * @param res
     */
    post(req: any, res: any) {
        throw new Error("Method not implemented.");
    }

    /**
     * METHOD DELETE
     * @param req
     * @param res
     */
    delete(req: any, res: any) {
        throw new Error("Method not implemented.");
    }

    /**
     * METHOD PUT
     * @param req
     * @param res
     */
    put(req: any, res: any) {
        throw new Error("Method not implemented.");
    }

}

In this case, the following routes were created:

GET     /game
GET     /game/:id
POST    /game
PUT     /game/:id
DELETE  /game/:id

All routes are created in lower case.

Middleware

The middleware attribute of the class is a reserved attribute. If it is a public api, just make the attribute null.

import {ControllerInterface} from "https://deno.land/x/mvc@v0.0.10/mod.ts";

export class Game implements ControllerInterface {
    
    middleware = null;
    
    ...
}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published
0