Class: Vertx::RouteMatcher
- Inherits:
-
Object
- Object
- Vertx::RouteMatcher
- Defined in:
- src/main/api_shim/core/http.rb
Overview
This class allows you to do route requests based on the HTTP verb and the request URI, in a manner similar
to <a href="http://www.sinatrarb.com/">Sinatra</a> or <a href="http://expressjs.com/">Express</a>.
RouteMatcher also lets you extract parameters from the request URI either a simple pattern or using
regular expressions for more complex matches. Any parameters extracted will be added to the requests parameters
which will be available to you in your request handler.
It's particularly useful when writing REST-ful web applications.
To use a simple pattern to extract parameters simply prefix the parameter name in the pattern with a ':' (colon).
Different handlers can be specified for each of the HTTP verbs, GET, POST, PUT, DELETE etc.
For more complex matches regular expressions can be used in the pattern. When regular expressions are used, the extracted
parameters do not have a name, so they are put into the HTTP request with names of param0, param1, param2 etc.
Multiple matches can be specified for each HTTP verb. In the case there are more than one matching patterns for
a particular request, the first matching one will be used.
Instance Method Summary (collapse)
-
- (Object) all(pattern, &hndlr)
Specify a handler that will be called for any matching HTTP request.
-
- (Object) all_re(pattern, &hndlr)
Specify a handler that will be called for any matching HTTP request.
-
- (Object) connect(pattern, &hndlr)
Specify a handler that will be called for a matching HTTP CONNECT.
-
- (Object) connect_re(pattern, &hndlr)
Specify a handler that will be called for a matching HTTP CONNECT.
-
- (Object) delete(pattern, &hndlr)
Specify a handler that will be called for a matching HTTP DELETE.
-
- (Object) delete_re(pattern, &hndlr)
Specify a handler that will be called for a matching HTTP DELETE.
-
- (Object) get(pattern, &hndlr)
Specify a handler that will be called for a matching HTTP GET.
-
- (Object) get_re(pattern, &hndlr)
Specify a handler that will be called for a matching HTTP GET.
-
- (Object) head(pattern, &hndlr)
Specify a handler that will be called for a matching HTTP HEAD.
-
- (Object) head_re(pattern, &hndlr)
Specify a handler that will be called for a matching HTTP HEAD.
-
- (RouteMatcher) initialize
constructor
A new instance of RouteMatcher.
-
- (Object) input(request)
This method is called to provide the matcher with data.
-
- (Object) no_match(&hndlr)
Specify a handler that will be called when nothing matches Default behaviour is to return a 404.
-
- (Object) options(pattern, &hndlr)
Specify a handler that will be called for a matching HTTP OPTIONS.
-
- (Object) options_re(pattern, &hndlr)
Specify a handler that will be called for a matching HTTP OPTIONS.
-
- (Object) patch(pattern, &hndlr)
Specify a handler that will be called for a matching HTTP PATCH.
-
- (Object) patch_re(pattern, &hndlr)
Specify a handler that will be called for a matching HTTP PATCH.
-
- (Object) post(pattern, &hndlr)
Specify a handler that will be called for a matching HTTP POST.
-
- (Object) post_re(pattern, &hndlr)
Specify a handler that will be called for a matching HTTP POST.
-
- (Object) put(pattern, &hndlr)
Specify a handler that will be called for a matching HTTP PUT.
-
- (Object) put_re(pattern, &hndlr)
Specify a handler that will be called for a matching HTTP PUT.
-
- (Object) trace(pattern, &hndlr)
Specify a handler that will be called for a matching HTTP TRACE.
-
- (Object) trace_re(pattern, proc = nil, &hndlr)
Specify a handler that will be called for a matching HTTP TRACE.
Constructor Details
- (RouteMatcher) initialize
A new instance of RouteMatcher
890 891 892 |
# File 'src/main/api_shim/core/http.rb', line 890 def initialize @j_del = org.vertx.java.core.http.RouteMatcher.new end |
Instance Method Details
- (Object) all(pattern, &hndlr)
Specify a handler that will be called for any matching HTTP request
966 967 968 |
# File 'src/main/api_shim/core/http.rb', line 966 def all(pattern, &hndlr) @j_del.all(pattern) { |j_req| hndlr.call(HttpServerRequest.new(j_req)) } end |
- (Object) all_re(pattern, &hndlr)
Specify a handler that will be called for any matching HTTP request
1037 1038 1039 |
# File 'src/main/api_shim/core/http.rb', line 1037 def all_re(pattern, &hndlr) @j_del.allWithRegEx(pattern) { |j_req| hndlr.call(HttpServerRequest.new(j_req)) } end |
- (Object) connect(pattern, &hndlr)
Specify a handler that will be called for a matching HTTP CONNECT
959 960 961 |
# File 'src/main/api_shim/core/http.rb', line 959 def connect(pattern, &hndlr) @j_del.connect(pattern) { |j_req| hndlr.call(HttpServerRequest.new(j_req)) } end |
- (Object) connect_re(pattern, &hndlr)
Specify a handler that will be called for a matching HTTP CONNECT
1030 1031 1032 |
# File 'src/main/api_shim/core/http.rb', line 1030 def connect_re(pattern, &hndlr) @j_del.connectWithRegEx(pattern) { |j_req| hndlr.call(HttpServerRequest.new(j_req)) } end |
- (Object) delete(pattern, &hndlr)
Specify a handler that will be called for a matching HTTP DELETE
924 925 926 |
# File 'src/main/api_shim/core/http.rb', line 924 def delete(pattern, &hndlr) @j_del.delete(pattern) { |j_req| hndlr.call(HttpServerRequest.new(j_req)) } end |
- (Object) delete_re(pattern, &hndlr)
Specify a handler that will be called for a matching HTTP DELETE
995 996 997 |
# File 'src/main/api_shim/core/http.rb', line 995 def delete_re(pattern, &hndlr) @j_del.deleteWithRegEx(pattern) { |j_req| hndlr.call(HttpServerRequest.new(j_req)) } end |
- (Object) get(pattern, &hndlr)
Specify a handler that will be called for a matching HTTP GET
903 904 905 |
# File 'src/main/api_shim/core/http.rb', line 903 def get(pattern, &hndlr) @j_del.get(pattern) { |j_req| hndlr.call(HttpServerRequest.new(j_req)) } end |
- (Object) get_re(pattern, &hndlr)
Specify a handler that will be called for a matching HTTP GET
973 974 975 976 |
# File 'src/main/api_shim/core/http.rb', line 973 def get_re(pattern, &hndlr) @j_del.getWithRegEx(pattern) { |j_req| hndlr.call(HttpServerRequest.new(j_req)) } end |
- (Object) head(pattern, &hndlr)
Specify a handler that will be called for a matching HTTP HEAD
938 939 940 |
# File 'src/main/api_shim/core/http.rb', line 938 def head(pattern, &hndlr) @j_del.head(pattern) { |j_req| hndlr.call(HttpServerRequest.new(j_req)) } end |
- (Object) head_re(pattern, &hndlr)
Specify a handler that will be called for a matching HTTP HEAD
1009 1010 1011 |
# File 'src/main/api_shim/core/http.rb', line 1009 def head_re(pattern, &hndlr) @j_del.headWithRegEx(pattern) { |j_req| hndlr.call(HttpServerRequest.new(j_req)) } end |
- (Object) input(request)
This method is called to provide the matcher with data.
896 897 898 |
# File 'src/main/api_shim/core/http.rb', line 896 def input(request) @j_del.handle(request._to_java_request) end |
- (Object) no_match(&hndlr)
Specify a handler that will be called when nothing matches
Default behaviour is to return a 404
1044 1045 1046 |
# File 'src/main/api_shim/core/http.rb', line 1044 def no_match(&hndlr) @j_del.noMatch { |j_req| hndlr.call(HttpServerRequest.new(j_req)) } end |
- (Object) options(pattern, &hndlr)
Specify a handler that will be called for a matching HTTP OPTIONS
931 932 933 |
# File 'src/main/api_shim/core/http.rb', line 931 def (pattern, &hndlr) @j_del.(pattern) { |j_req| hndlr.call(HttpServerRequest.new(j_req)) } end |
- (Object) options_re(pattern, &hndlr)
Specify a handler that will be called for a matching HTTP OPTIONS
1002 1003 1004 |
# File 'src/main/api_shim/core/http.rb', line 1002 def (pattern, &hndlr) @j_del.(pattern) { |j_req| hndlr.call(HttpServerRequest.new(j_req)) } end |
- (Object) patch(pattern, &hndlr)
Specify a handler that will be called for a matching HTTP PATCH
952 953 954 |
# File 'src/main/api_shim/core/http.rb', line 952 def patch(pattern, &hndlr) @j_del.patch(pattern) { |j_req| hndlr.call(HttpServerRequest.new(j_req)) } end |
- (Object) patch_re(pattern, &hndlr)
Specify a handler that will be called for a matching HTTP PATCH
1023 1024 1025 |
# File 'src/main/api_shim/core/http.rb', line 1023 def patch_re(pattern, &hndlr) @j_del.patchWithRegEx(pattern) { |j_req| hndlr.call(HttpServerRequest.new(j_req)) } end |
- (Object) post(pattern, &hndlr)
Specify a handler that will be called for a matching HTTP POST
917 918 919 |
# File 'src/main/api_shim/core/http.rb', line 917 def post(pattern, &hndlr) @j_del.post(pattern) { |j_req| hndlr.call(HttpServerRequest.new(j_req)) } end |
- (Object) post_re(pattern, &hndlr)
Specify a handler that will be called for a matching HTTP POST
988 989 990 |
# File 'src/main/api_shim/core/http.rb', line 988 def post_re(pattern, &hndlr) @j_del.postWithRegEx(pattern) { |j_req| hndlr.call(HttpServerRequest.new(j_req)) } end |
- (Object) put(pattern, &hndlr)
Specify a handler that will be called for a matching HTTP PUT
910 911 912 |
# File 'src/main/api_shim/core/http.rb', line 910 def put(pattern, &hndlr) @j_del.put(pattern) { |j_req| hndlr.call(HttpServerRequest.new(j_req)) } end |
- (Object) put_re(pattern, &hndlr)
Specify a handler that will be called for a matching HTTP PUT
981 982 983 |
# File 'src/main/api_shim/core/http.rb', line 981 def put_re(pattern, &hndlr) @j_del.putWithRegEx(pattern) { |j_req| hndlr.call(HttpServerRequest.new(j_req)) } end |
- (Object) trace(pattern, &hndlr)
Specify a handler that will be called for a matching HTTP TRACE
945 946 947 |
# File 'src/main/api_shim/core/http.rb', line 945 def trace(pattern, &hndlr) @j_del.trace(pattern) { |j_req| hndlr.call(HttpServerRequest.new(j_req)) } end |
- (Object) trace_re(pattern, proc = nil, &hndlr)
Specify a handler that will be called for a matching HTTP TRACE
1016 1017 1018 |
# File 'src/main/api_shim/core/http.rb', line 1016 def trace_re(pattern, proc = nil, &hndlr) @j_del.traceWithRegEx(pattern) { |j_req| hndlr.call(HttpServerRequest.new(j_req)) } end |