Class: Vertx::RouteMatcher

Inherits:
Object
  • Object
show all
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.

Author:

Instance Method Summary (collapse)

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

Parameters:

  • The (String)
    simple pattern
  • hndlr (Block)
    A block to be used as the handler


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

Parameters:

  • A (String)
    regular expression for a pattern
  • hndlr (Block)
    A block to be used as the handler


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

Parameters:

  • The (String)
    simple pattern
  • hndlr (Block)
    A block to be used as the handler


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

Parameters:

  • A (String)
    regular expression for a pattern
  • hndlr (Block)
    A block to be used as the handler


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

Parameters:

  • The (String)
    simple pattern
  • hndlr (Block)
    A block to be used as the handler


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

Parameters:

  • A (String)
    regular expression for a pattern
  • hndlr (Block)
    A block to be used as the handler


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

Parameters:

  • The (String)
    simple pattern
  • hndlr (Block)
    A block to be used as the handler


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

Parameters:

  • A (String)
    regular expression for a pattern
  • hndlr (Block)
    A block to be used as the handler


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

Parameters:

  • The (String)
    simple pattern
  • hndlr (Block)
    A block to be used as the handler


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

Parameters:

  • A (String)
    regular expression for a pattern
  • hndlr (Block)
    A block to be used as the handler


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.

Parameters:



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

Parameters:

  • hndlr (Block)
    A block to be used as the handler


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

Parameters:

  • The (String)
    simple pattern
  • hndlr (Block)
    A block to be used as the handler


931
932
933
# File 'src/main/api_shim/core/http.rb', line 931

def options(pattern, &hndlr)
  @j_del.options(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

Parameters:

  • A (String)
    regular expression for a pattern
  • hndlr (Block)
    A block to be used as the handler


1002
1003
1004
# File 'src/main/api_shim/core/http.rb', line 1002

def options_re(pattern, &hndlr)
  @j_del.optionsWithRegEx(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

Parameters:

  • The (String)
    simple pattern
  • hndlr (Block)
    A block to be used as the handler


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

Parameters:

  • A (String)
    regular expression for a pattern
  • hndlr (Block)
    A block to be used as the handler


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

Parameters:

  • The (String)
    simple pattern
  • hndlr (Block)
    A block to be used as the handler


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

Parameters:

  • A (String)
    regular expression for a pattern
  • hndlr (Block)
    A block to be used as the handler


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

Parameters:

  • The (String)
    simple pattern
  • hndlr (Block)
    A block to be used as the handler


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

Parameters:

  • A (String)
    regular expression for a pattern
  • hndlr (Block)
    A block to be used as the handler


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

Parameters:

  • The (String)
    simple pattern
  • hndlr (Block)
    A block to be used as the handler


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

Parameters:

  • A (String)
    regular expression for a pattern
  • hndlr (Block)
    A block to be used as the handler


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