A small service that parses the whole request body (currently it is working only with the query params), it is meant to run the whole request against a set of rules (as anonymous functions) and determine where to redirect the request body. This is my first ever elixir project, so I intent to extend it more and make it more usable.
# Start the process, that will hold the rules UrlParser.Rule.start_agent # Add some rules function = fn(request) -> String.match?(request, ~r/query/) end UrlParser.Rule.add(:query, function) uri = "http://test.com/?query=omg" # If the url satisfies the rule UrlParser.parse(uri) => [ok: :query] # If the url does not satisfy the rule. UrlParser.parse(uri) => [{:not_ok, "Rules do not match"}]
If available in Hex, the package can be installed as:
- Add
url_parserto your list of dependencies inmix.exs:
```elixir
def deps do
[{:url_parser, "~> 0.1.0"}]
end
```
- Ensure
url_parseris started before your application:
```elixir
def application do
[applications: [:url_parser]]
end
```