Skip to content

API without invoking handlers #28

@kirs

Description

@kirs

Hey there! Thank you for this awesome library.

I'm interested in using it in nginx as a router, but for what I'm looking to do, I don't want to invoke a route handler when a route is matched. All I want is to match a request to a route, and lookup that route's metadata.

An example in pseudocode:

local r3route = require "resty.r3"
local r3 = r3route.new({
  {
      path = [[/foo/{:\w+}/{:\w+}"]],
      method = {"GET"},
      metadata = { server: foo, datacenter: us-east }
  },
  {
      path = [[/bar/{:\w+}/{:\w+}]],
      host = "*.bar.com",
      metadata = { server: bar, datacenter: us-east }
  },
  {
      path = [[/alice/{:\w+}/{:\w+}]],
      metadata = { server: alice, datacenter: us-west }
  },
})

-- match_route is imaginary name, similar API to r3:dispatch
local metadata = r3:match_route("GET", "/alice/one/two")

metadata.server => alice
metadata.datacenter => us-west

I think this is very similar to existing API, with one difference in handler vs. metadata.
I'd be happy to contribute a patch once other contributors are onboard 👍

cc @membphis

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions