Skip to content

Arbitrium is a web micro-framework for Deno. It's designed to create a MVC controllers, making available an async web server and a router, to make get started a powerful applications.

License

Notifications You must be signed in to change notification settings

guilhermewebdev/arbitrium

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

81 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Arbitrium

Arbitrium is a web micro-framework for Deno. It's designed to create a MVC controllers, making available an async web server and a router, to make get started a powerful applications.

A Simple Example

import Server, {
    RequestListener,
    Response
} from 'https://deno.land/x/arbitrium@v0.1.0-alpha.2/src/server.ts';
import Router from 'https://deno.land/x/arbitrium@v0.1.0-alpha.2/src/router.ts';
import { route } from 'https://deno.land/x/arbitrium@v0.1.0-alpha.2/src/route.ts';
import { ServerRequest } from "https://deno.land/std@0.80.0/http/server.ts";

async function view(request: ServerRequest, args?: {}) {
    // Write views to process the request, and return a response
    return new Response('Hello World');
}

async function viewWithParam(request: ServerRequest, args?: {}) {
    // You can get the url params from "args" variable
    return new Response(args, 200, 'application/json')
}

const router = new Router([
    // You can set the routes to call a view
    route('/', view),
    // You can pass url params
    route('/<id:number>', viewWithParam),
])

function middleware(getResponse: RequestListener){
    // One-time configuration and initialization.
    console.log('On Start Application')
    return async function(request: ServerRequest) {
        // Code to be executed for each request before
        // the view (and later middleware) are called.
        console.log('On Request')
        const response = await getResponse(request);
        // Code to be executed for each request/response after
        // the view is called.
        console.log('On Response')
        return response;
    }
}

// To create a server, is just instance the "Server" class with configs
const server = new Server({ router, middlewares: [middleware] });

// To start server is just call the ".listen()" Server method
server.listen()
$ deno --allow-net example/simple.ts
    Check file:///path/to/arbitrium/example/simple.ts
    On Start Application
    [SERVER RUNNING]: ON http://localhost:8080 (Press CTRL+C to quit)
    

About

Arbitrium is a web micro-framework for Deno. It's designed to create a MVC controllers, making available an async web server and a router, to make get started a powerful applications.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published