Class: Vertx::RouteMatcher
- Inherits:
-
Object
- Object
- Vertx::RouteMatcher
- Defined in:
- src/main/ruby_scripts/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 paramaters 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, proc = nil, &hndlr)
Specify a handler that will be called for any matching HTTP request.
-
- (Object) all_re(pattern, proc = nil, &hndlr)
Specify a handler that will be called for any matching HTTP request.
-
- (Object) connect(pattern, proc = nil, &hndlr)
Specify a handler that will be called for a matching HTTP CONNECT.
-
- (Object) connect_re(pattern, proc = nil, &hndlr)
Specify a handler that will be called for a matching HTTP CONNECT.
-
- (Object) delete(pattern, proc = nil, &hndlr)
Specify a handler that will be called for a matching HTTP DELETE.
-
- (Object) delete_re(pattern, proc = nil, &hndlr)
Specify a handler that will be called for a matching HTTP DELETE.
-
- (Object) get(pattern, proc = nil, &hndlr)
Specify a handler that will be called for a matching HTTP GET.
-
- (Object) get_re(pattern, proc = nil, &hndlr)
Specify a handler that will be called for a matching HTTP GET.
-
- (Object) head(pattern, proc = nil, &hndlr)
Specify a handler that will be called for a matching HTTP HEAD.
-
- (Object) head_re(pattern, proc = nil, &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(proc = nil, &hndlr)
Specify a handler that will be called when nothing matches Default behaviour is to return a 404.
-
- (Object) options(pattern, proc = nil, &hndlr)
Specify a handler that will be called for a matching HTTP OPTIONS.
-
- (Object) options_re(pattern, proc = nil, &hndlr)
Specify a handler that will be called for a matching HTTP OPTIONS.
-
- (Object) patch(pattern, proc = nil, &hndlr)
Specify a handler that will be called for a matching HTTP PATCH.
-
- (Object) patch_re(pattern, proc = nil, &hndlr)
Specify a handler that will be called for a matching HTTP PATCH.
-
- (Object) post(pattern, proc = nil, &hndlr)
Specify a handler that will be called for a matching HTTP POST.
-
- (Object) post_re(pattern, proc = nil, &hndlr)
Specify a handler that will be called for a matching HTTP POST.
-
- (Object) put(pattern, proc = nil, &hndlr)
Specify a handler that will be called for a matching HTTP PUT.
-
- (Object) put_re(pattern, proc = nil, &hndlr)
Specify a handler that will be called for a matching HTTP PUT.
-
- (Object) trace(pattern, proc = nil, &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
787 788 789 |
# File 'src/main/ruby_scripts/core/http.rb', line 787 def initialize @j_del = org.vertx.java.core.http.RouteMatcher.new end |
Instance Method Details
- (Object) all(pattern, proc = nil, &hndlr)
Specify a handler that will be called for any matching HTTP request
887 888 889 890 |
# File 'src/main/ruby_scripts/core/http.rb', line 887 def all(pattern, proc = nil, &hndlr) hndlr = proc if proc @j_del.all(pattern) { |j_req| hndlr.call(HttpServerRequest.new(j_req)) } end |
- (Object) all_re(pattern, proc = nil, &hndlr)
Specify a handler that will be called for any matching HTTP request
977 978 979 980 |
# File 'src/main/ruby_scripts/core/http.rb', line 977 def all_re(pattern, proc = nil, &hndlr) hndlr = proc if proc @j_del.allWithRegEx(pattern) { |j_req| hndlr.call(HttpServerRequest.new(j_req)) } end |
- (Object) connect(pattern, proc = nil, &hndlr)
Specify a handler that will be called for a matching HTTP CONNECT
878 879 880 881 |
# File 'src/main/ruby_scripts/core/http.rb', line 878 def connect(pattern, proc = nil, &hndlr) hndlr = proc if proc @j_del.connect(pattern) { |j_req| hndlr.call(HttpServerRequest.new(j_req)) } end |
- (Object) connect_re(pattern, proc = nil, &hndlr)
Specify a handler that will be called for a matching HTTP CONNECT
968 969 970 971 |
# File 'src/main/ruby_scripts/core/http.rb', line 968 def connect_re(pattern, proc = nil, &hndlr) hndlr = proc if proc @j_del.connectWithRegEx(pattern) { |j_req| hndlr.call(HttpServerRequest.new(j_req)) } end |
- (Object) delete(pattern, proc = nil, &hndlr)
Specify a handler that will be called for a matching HTTP DELETE
833 834 835 836 |
# File 'src/main/ruby_scripts/core/http.rb', line 833 def delete(pattern, proc = nil, &hndlr) hndlr = proc if proc @j_del.delete(pattern) { |j_req| hndlr.call(HttpServerRequest.new(j_req)) } end |
- (Object) delete_re(pattern, proc = nil, &hndlr)
Specify a handler that will be called for a matching HTTP DELETE
923 924 925 926 |
# File 'src/main/ruby_scripts/core/http.rb', line 923 def delete_re(pattern, proc = nil, &hndlr) hndlr = proc if proc @j_del.deleteWithRegEx(pattern) { |j_req| hndlr.call(HttpServerRequest.new(j_req)) } end |
- (Object) get(pattern, proc = nil, &hndlr)
Specify a handler that will be called for a matching HTTP GET
806 807 808 809 |
# File 'src/main/ruby_scripts/core/http.rb', line 806 def get(pattern, proc = nil, &hndlr) hndlr = proc if proc @j_del.get(pattern) { |j_req| hndlr.call(HttpServerRequest.new(j_req)) } end |
- (Object) get_re(pattern, proc = nil, &hndlr)
Specify a handler that will be called for a matching HTTP GET
896 897 898 899 |
# File 'src/main/ruby_scripts/core/http.rb', line 896 def get_re(pattern, proc = nil, &hndlr) hndlr = proc if proc @j_del.getWithRegEx(pattern) { |j_req| hndlr.call(HttpServerRequest.new(j_req)) } end |
- (Object) head(pattern, proc = nil, &hndlr)
Specify a handler that will be called for a matching HTTP HEAD
851 852 853 854 |
# File 'src/main/ruby_scripts/core/http.rb', line 851 def head(pattern, proc = nil, &hndlr) hndlr = proc if proc @j_del.head(pattern) { |j_req| hndlr.call(HttpServerRequest.new(j_req)) } end |
- (Object) head_re(pattern, proc = nil, &hndlr)
Specify a handler that will be called for a matching HTTP HEAD
941 942 943 944 |
# File 'src/main/ruby_scripts/core/http.rb', line 941 def head_re(pattern, proc = nil, &hndlr) hndlr = proc if proc @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.
798 799 800 |
# File 'src/main/ruby_scripts/core/http.rb', line 798 def input(request) @j_del.handle(request._to_java_request) end |
- (Object) no_match(proc = nil, &hndlr)
Specify a handler that will be called when nothing matches Default behaviour is to return a 404
986 987 988 989 |
# File 'src/main/ruby_scripts/core/http.rb', line 986 def no_match(proc = nil, &hndlr) hndlr = proc if proc @j_del.noMatch { |j_req| hndlr.call(HttpServerRequest.new(j_req)) } end |
- (Object) options(pattern, proc = nil, &hndlr)
Specify a handler that will be called for a matching HTTP OPTIONS
842 843 844 845 |
# File 'src/main/ruby_scripts/core/http.rb', line 842 def (pattern, proc = nil, &hndlr) hndlr = proc if proc @j_del.(pattern) { |j_req| hndlr.call(HttpServerRequest.new(j_req)) } end |
- (Object) options_re(pattern, proc = nil, &hndlr)
Specify a handler that will be called for a matching HTTP OPTIONS
932 933 934 935 |
# File 'src/main/ruby_scripts/core/http.rb', line 932 def (pattern, proc = nil, &hndlr) hndlr = proc if proc @j_del.(pattern) { |j_req| hndlr.call(HttpServerRequest.new(j_req)) } end |
- (Object) patch(pattern, proc = nil, &hndlr)
Specify a handler that will be called for a matching HTTP PATCH
869 870 871 872 |
# File 'src/main/ruby_scripts/core/http.rb', line 869 def patch(pattern, proc = nil, &hndlr) hndlr = proc if proc @j_del.patch(pattern) { |j_req| hndlr.call(HttpServerRequest.new(j_req)) } end |
- (Object) patch_re(pattern, proc = nil, &hndlr)
Specify a handler that will be called for a matching HTTP PATCH
959 960 961 962 |
# File 'src/main/ruby_scripts/core/http.rb', line 959 def patch_re(pattern, proc = nil, &hndlr) hndlr = proc if proc @j_del.patchWithRegEx(pattern) { |j_req| hndlr.call(HttpServerRequest.new(j_req)) } end |
- (Object) post(pattern, proc = nil, &hndlr)
Specify a handler that will be called for a matching HTTP POST
824 825 826 827 |
# File 'src/main/ruby_scripts/core/http.rb', line 824 def post(pattern, proc = nil, &hndlr) hndlr = proc if proc @j_del.post(pattern) { |j_req| hndlr.call(HttpServerRequest.new(j_req)) } end |
- (Object) post_re(pattern, proc = nil, &hndlr)
Specify a handler that will be called for a matching HTTP POST
914 915 916 917 |
# File 'src/main/ruby_scripts/core/http.rb', line 914 def post_re(pattern, proc = nil, &hndlr) hndlr = proc if proc @j_del.postWithRegEx(pattern) { |j_req| hndlr.call(HttpServerRequest.new(j_req)) } end |
- (Object) put(pattern, proc = nil, &hndlr)
Specify a handler that will be called for a matching HTTP PUT
815 816 817 818 |
# File 'src/main/ruby_scripts/core/http.rb', line 815 def put(pattern, proc = nil, &hndlr) hndlr = proc if proc @j_del.put(pattern) { |j_req| hndlr.call(HttpServerRequest.new(j_req)) } end |
- (Object) put_re(pattern, proc = nil, &hndlr)
Specify a handler that will be called for a matching HTTP PUT
905 906 907 908 |
# File 'src/main/ruby_scripts/core/http.rb', line 905 def put_re(pattern, proc = nil, &hndlr) hndlr = proc if proc @j_del.putWithRegEx(pattern) { |j_req| hndlr.call(HttpServerRequest.new(j_req)) } end |
- (Object) trace(pattern, proc = nil, &hndlr)
Specify a handler that will be called for a matching HTTP TRACE
860 861 862 863 |
# File 'src/main/ruby_scripts/core/http.rb', line 860 def trace(pattern, proc = nil, &hndlr) hndlr = proc if proc @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
950 951 952 953 |
# File 'src/main/ruby_scripts/core/http.rb', line 950 def trace_re(pattern, proc = nil, &hndlr) hndlr = proc if proc @j_del.traceWithRegEx(pattern) { |j_req| hndlr.call(HttpServerRequest.new(j_req)) } end |