Giter Club home page Giter Club logo

lua-resty-oakrouting's Introduction

Name

lua-resty-oakrouting - The APIOAK Routing component

Table of Contents

Synopsis

location / {
    content_by_lua_block {
        local oakrouting  = require("resty.oakrouting")
        local oak_routing = oakrouting.new({
            {
                path = "/test/get",
                method = "GET",
                handler = function()
                    ngx.say("hello, GET")
                end
            },
            {
                path = "/test/post",
                method = "POST",
                handler = function()
                    ngx.say("hello, POST")
                end
            },
            {
                path = "/test/put",
                method = "PUT",
                handler = function()
                    ngx.say("hello, PUT")
                end
            },
            {
                path = "/test/delete",
                method = "DELETE",
                handler = function()
                    ngx.say("hello, DELETE")
                end
            },
            {
                path = "/test/parameter/{gateway}",
                method = "DELETE",
                handler = function(params)
                    ngx.say("hello, " .. params.gateway)
                end
            },
        })
        
        
        local succeed = oak:dispatch("/test/get", "GET")
        if not succeed then
            ngx.say("Matched URI: /test/get FAIL")
        end


        succeed = oak:dispatch("/test/post", "POST")
        if not succeed then
            ngx.say("Matched URI: /test/post FAIL")
        end


        succeed = oak:dispatch("/test/put", "PUT")
        if not succeed then
            ngx.say("Matched URI: /test/put FAIL")
        end


        succeed = oak:dispatch("/test/delete", "DELETE")
        if not succeed then
            ngx.say("Matched URI: /test/delete FAIL")
        end
        
        succeed = oak:dispatch("/test/parameter/apioak", "GET")
        if not succeed then
            ngx.say("Matched URI: /test/parameter/apioak FAIL")
        end     
    }
}

Methods

new

syntax: res, err = oakrouting:new(routers)

Create and initialize a routing object.

get

syntax: oakrouting:get(path, handler)

Added GET method routing.

post

syntax: oakrouting:post(path, handler)

Added POST method routing.

put

syntax: oakrouting:put(path, handler)

Added PUT method routing.

delete

syntax: oakrouting:delete(path, handler)

Added DELETE method routing.

any

syntax: oakrouting:any(method, path, handler)

Added custom routing.

dispatch

syntax: succeed = oakrouting:dispatch(path, method)

Match the routing path and execute the handle.

Installation

Installation via LuaRocks

sudo luarocks install lua-resty-oakrouting

lua-resty-oakrouting's People

Contributors

shuaijinchao avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.