View Source GRPC.Server.Router (grpc v0.9.0)
Summary
Functions
Builds a t:route/0 from a URL path or t:Google.Api.Http.t/0
.
Matches a URL path or URL segements against a compiled route matcher. Matched bindings from the segments are extracted into a map. If the same variable name is used in multiple bindings, the value must match otherwise the route is not considered a match.
Split URL path into segments, removing the leading and trailing slash.
Types
@type http_method() :: :get | :put | :post | :patch | :delete
@type route() :: {http_method(), String.t(), GRPC.Server.Router.Template.matchers()}
Functions
Builds a t:route/0 from a URL path or t:Google.Api.Http.t/0
.
The matcher part in the route can be used in match/3
to match on a URL path or a list of segments.
Examples
{:get, "/v1/messages/{message_id}", match} = GRPC.Server.Router.build_route(:get, "/v1/messages/{message_id}")
{:get, path, match} = GRPC.Server.Router.build_route(:get, "/v1/{book.location=shelves/*}/books/{book.name=*}")
{true, %{"book.location": "shelves/example-shelf", "book.name": "example-book"}} = GRPC.Server.Router.match("/v1/shelves/example-shelf/books/example-book", match, [])
@spec match(String.t() | [String.t()], GRPC.Server.Router.Template.matchers()) :: {true, map()} | false
Matches a URL path or URL segements against a compiled route matcher. Matched bindings from the segments are extracted into a map. If the same variable name is used in multiple bindings, the value must match otherwise the route is not considered a match.
Examples
{_, _, match} = GRPC.Server.Router.build_route(:get, "/v1/{name=messages}")
{true, %{name: "messages"}} = GRPC.Server.Router.match("/v1/messages", match)
false = GRPC.Server.Router.match("/v1/messages/foobar", match)
{_, _, match} = GRPC.Server.Router.build_route(:get, "/v1/{name=shelves/*/books/*)
{true, %{name: "shelves/books/book"}} = GRPC.Server.Router.match("/v1/shelves/example-shelf/books/book", match)
false = GRPC.Server.Router.match("/v1/shelves/example-shelf/something-els/books/book", match)
Split URL path into segments, removing the leading and trailing slash.
Examples
["v1", "messages"] = GRPC.Server.Router.split_path("/v1/messages")