virtkick/http-master

Route by HTTP Method

Opened this issue · 15 comments

Is it possible to route based on HTTP Method, e.g. GET/POST ?

Rush commented

Not yet, no. That's a good idea though and a good candidate for extension for the router module. Are you using http-master from code or standalone?

I'm using it from code:
init
routing

Rush commented

What syntax do you propose for this functionality?

{
":inbox_tray:domain/* ": "3000/get/[1]",
":postbox:domain/* ": "2000/post/[1]"
}

json supports emoji, right? 👻

Rush commented

🐰

So i don't have much experience with this project -- what characters are not parsed currently?

this seems straightforward enough, but might conflict a bit

{
"GET:domain/* ": "3000/get/[1]",
"POST:domain/* ": "2000/post/[1]"
}

we could do whatever is easiest really

{
"GET=domain/* ": "3000/get/[1]",
"POST=domain/* ": "2000/post/[1]"
}

and i mean easiest not just out of laziness but also keeping the code simple and maintainable

Rush commented

how about this?

ports: {
  80: {
    router: {
      'domain/*': {
        GET: '3000/get/[1]',
        POST: '2000/post/[1]'
      }
    }
  }
}

@Rush CAPS is waste of keystrokes, btw, get or post would be sufficient and equally semantic. :)

Rush commented

Caps are needed to differentiate domains from http actions. Domains would be low caps.

i like that expansion. would you need to differentiate if you were using an object like that?

ports: {
  "80": {
    "router": {
      "domain/*": {
        "domain": "3000/get/[1]",
        "ACTION": "2000/post/[1]"
      }
    }
  }
}
Rush commented

In your example "domain" is already matched so it would be:

ports: {
  "80": {
    "router": {
      "domain/*": {
        "ACTION": "2000/post/[1]",
        "*": "3000/get/[1]"
      }
    }
  }
}

@Rush But domain is already defined in "domain/*", so having another domain one level deeper doesn't make sense, no?

Rush commented

If the "domain" matches couple of times no harm is done but as I've posted, it wouldn't be necessary.

👍 😸