# `GRPC.Server.Router`
[🔗](https://github.com/elixir-grpc/grpc_server/blob/v1.0.1/lib/grpc/server/router.ex#L1)

# `http_method`

```elixir
@type http_method() :: :get | :put | :post | :patch | :delete
```

# `route`

```elixir
@type route() :: {http_method(), String.t(), GRPC.Server.Router.Template.matchers()}
```

# `build_route`

```elixir
@spec build_route(binary() | map()) :: route()
```

# `build_route`

```elixir
@spec build_route(atom(), binary()) :: route()
```

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, [])

# `match`

```elixir
@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)

# `match`

```elixir
@spec match(String.t() | [String.t()], GRPC.Server.Router.Template.matchers(), map()) ::
  {true, map()} | false
```

# `split_path`

```elixir
@spec split_path(String.t()) :: iolist()
```

Split URL path into segments, removing the leading and trailing slash.

## Examples

     ["v1", "messages"] = GRPC.Server.Router.split_path("/v1/messages")

---

*Consult [api-reference.md](api-reference.md) for complete listing*
