cowboy_router.compile.asciidoc 955 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. = cowboy_router:compile(3)
  2. == Name
  3. cowboy_router:compile - Compile routes to the resources
  4. == Description
  5. [source,erlang]
  6. ----
  7. compile(cowboy_router:routes()) -> cowboy_router:dispatch_rules()
  8. ----
  9. Compile routes to the resources.
  10. Takes a human readable list of routes and transforms it
  11. into a form more efficient to process.
  12. == Arguments
  13. Routes::
  14. Human readable list of routes.
  15. == Return value
  16. An opaque dispatch rules value is returned. This value
  17. must be given to Cowboy as a middleware environment value.
  18. == Changelog
  19. * *1.0*: Function introduced.
  20. == Examples
  21. .Compile routes and start a listener
  22. [source,erlang]
  23. ----
  24. Dispatch = cowboy_router:compile([
  25. {'_', [
  26. {"/", toppage_h, []},
  27. {"/[...], cowboy_static, {priv_dir, my_example_app, ""}}
  28. ]}
  29. ]),
  30. {ok, _} = cowboy:start_clear(example, 100, [{port, 8080}], #{
  31. env => #{dispatch => Dispatch}
  32. }).
  33. ----
  34. == See also
  35. link:man:cowboy_router(3)[cowboy_router(3)]