# Wrouter Erlang Bindings
Erlang NIF bindings for libwrouter.
## Installation
When published to Hex, add `wrouter` to `rebar.config`:
```erlang
{deps, [{wrouter, "1.0.1"}]}.
```
The package includes a native NIF and builds it with `make`, so users need
Erlang/OTP, rebar3, make, and a C compiler available at compile time.
## Usage
```erlang
Routes = [
{<<"/account">>, account_list},
{<<"/account/:id">>, account_view},
{<<"/posts/:id">>, fun handle_post/2}
],
{ok, Router} = wrouter:new(Routes),
{ok, Handler, Params} = wrouter:resolve(Router, <<"/account/1234">>).
```
`Handler` is the route context term supplied when building the router. It can
be an atom, tuple, map, function, or any other Erlang term. Parameters are
returned as a map of binaries.
## Development
The primary project build uses Meson. The Hex/rebar3 package uses a small
Makefile shim because that is the usual Erlang NIF packaging path and keeps
downstream build requirements minimal.
To build and test the Erlang package locally:
```sh
rebar3 compile
rebar3 eunit
```
To publish, install `rebar3_hex` in your global rebar3 config:
```erlang
{plugins, [rebar3_hex]}.
```
Create a Hex user API key with API write access, then export it before
publishing. With `rebar3_hex` 7.1.0, pass `--repo hexpm` so the plugin applies
`HEX_API_KEY` to the public Hex repository.
```sh
export HEX_API_KEY='hexpm_user_api_key'
rebar3 hex build
rebar3 hex publish package --repo hexpm --yes
```
Or pass the environment variable for a single command:
```sh
HEX_API_KEY='hexpm_user_api_key' rebar3 hex publish package --repo hexpm --yes
```
If the same version needs to be replaced within Hex's allowed replacement
window, add `--replace`:
```sh
HEX_API_KEY='hexpm_user_api_key' rebar3 hex publish package --repo hexpm --replace --yes
```