Class List Method List File List

# Class: Vertx::RouteMatcher

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

Author:

- Tim Fox

## 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

Parameters:

- The (`String`) —
  simple pattern
- proc (`Proc`) (defaults to: `nil`) —
  A proc to be used as the handler
- hndlr (`Block`) —
  A block to be used as the handler

    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

Parameters:

- A (`String`) —
  regular expression for a pattern
- proc (`Proc`) (defaults to: `nil`) —
  A proc to be used as the handler
- hndlr (`Block`) —
  A block to be used as the handler

    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

Parameters:

- The (`String`) —
  simple pattern
- proc (`Proc`) (defaults to: `nil`) —
  A proc to be used as the handler
- hndlr (`Block`) —
  A block to be used as the handler

    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

Parameters:

- A (`String`) —
  regular expression for a pattern
- proc (`Proc`) (defaults to: `nil`) —
  A proc to be used as the handler
- hndlr (`Block`) —
  A block to be used as the handler

    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

Parameters:

- The (`String`) —
  simple pattern
- proc (`Proc`) (defaults to: `nil`) —
  A proc to be used as the handler
- hndlr (`Block`) —
  A block to be used as the handler

    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

Parameters:

- A (`String`) —
  regular expression for a pattern
- proc (`Proc`) (defaults to: `nil`) —
  A proc to be used as the handler
- hndlr (`Block`) —
  A block to be used as the handler

    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

Parameters:

- The (`String`) —
  simple pattern
- proc (`Proc`) (defaults to: `nil`) —
  A proc to be used as the handler
- hndlr (`Block`) —
  A block to be used as the handler

    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

Parameters:

- A (`String`) —
  regular expression for a pattern
- proc (`Proc`) (defaults to: `nil`) —
  A proc to be used as the handler
- hndlr (`Block`) —
  A block to be used as the handler

    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

Parameters:

- The (`String`) —
  simple pattern
- proc (`Proc`) (defaults to: `nil`) —
  A proc to be used as the handler
- hndlr (`Block`) —
  A block to be used as the handler

    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

Parameters:

- A (`String`) —
  regular expression for a pattern
- proc (`Proc`) (defaults to: `nil`) —
  A proc to be used as the handler
- hndlr (`Block`) —
  A block to be used as the handler

    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.

Parameters:

- request. (`HttpServerRequest`) —
  Input request to the parser.

    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

Parameters:

- proc (`Proc`) (defaults to: `nil`) —
  A proc to be used as the handler
- hndlr (`Block`) —
  A block to be used as the handler

    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

Parameters:

- The (`String`) —
  simple pattern
- proc (`Proc`) (defaults to: `nil`) —
  A proc to be used as the handler
- hndlr (`Block`) —
  A block to be used as the handler

    842
    843
    844
    845

    # File 'src/main/ruby_scripts/core/http.rb', line 842

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

Parameters:

- A (`String`) —
  regular expression for a pattern
- proc (`Proc`) (defaults to: `nil`) —
  A proc to be used as the handler
- hndlr (`Block`) —
  A block to be used as the handler

    932
    933
    934
    935

    # File 'src/main/ruby_scripts/core/http.rb', line 932

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

Parameters:

- The (`String`) —
  simple pattern
- proc (`Proc`) (defaults to: `nil`) —
  A proc to be used as the handler
- hndlr (`Block`) —
  A block to be used as the handler

    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

Parameters:

- A (`String`) —
  regular expression for a pattern
- proc (`Proc`) (defaults to: `nil`) —
  A proc to be used as the handler
- hndlr (`Block`) —
  A block to be used as the handler

    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

Parameters:

- The (`String`) —
  simple pattern
- proc (`Proc`) (defaults to: `nil`) —
  A proc to be used as the handler
- hndlr (`Block`) —
  A block to be used as the handler

    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

Parameters:

- A (`String`) —
  regular expression for a pattern
- proc (`Proc`) (defaults to: `nil`) —
  A proc to be used as the handler
- hndlr (`Block`) —
  A block to be used as the handler

    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

Parameters:

- The (`String`) —
  simple pattern
- proc (`Proc`) (defaults to: `nil`) —
  A proc to be used as the handler
- hndlr (`Block`) —
  A block to be used as the handler

    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

Parameters:

- A (`String`) —
  regular expression for a pattern
- proc (`Proc`) (defaults to: `nil`) —
  A proc to be used as the handler
- hndlr (`Block`) —
  A block to be used as the handler

    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

Parameters:

- The (`String`) —
  simple pattern
- proc (`Proc`) (defaults to: `nil`) —
  A proc to be used as the handler
- hndlr (`Block`) —
  A block to be used as the handler

    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

Parameters:

- A (`String`) —
  regular expression for a pattern
- proc (`Proc`) (defaults to: `nil`) —
  A proc to be used as the handler
- hndlr (`Block`) —
  A block to be used as the handler

    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