virtkick / http-master

versatile front end http service with reverse proxy
MIT License
139 stars 17 forks source link

Route by HTTP Method #105

Open kumavis opened 9 years ago

kumavis commented 9 years ago

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

Rush commented 9 years ago

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?

kumavis commented 9 years ago

I'm using it from code: init routing

Rush commented 9 years ago

What syntax do you propose for this functionality?

kumavis commented 9 years ago

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

kumavis commented 9 years ago

json supports emoji, right? :ghost:

Rush commented 9 years ago

:rabbit:

kumavis commented 9 years ago

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 9 years ago

how about this?

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

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

Rush commented 9 years ago

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

kumavis commented 9 years ago

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 9 years ago

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

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

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

Rush commented 9 years ago

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

kumavis commented 9 years ago

:+1: :smile_cat: