cowboy_router.asciidoc 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. = cowboy_router(3)
  2. == Name
  3. cowboy_router - router middleware
  4. == Description
  5. The `cowboy_router` middleware maps the requested host and
  6. path to the handler to be used for processing the request.
  7. It uses the dispatch rules compiled from the routes given
  8. to the `compile/1` function for this purpose. It adds the
  9. handler name and options to the environment as the values
  10. `handler` and `handler_opts` respectively.
  11. === Environment input
  12. dispatch = dispatch_rules():: Dispatch table.
  13. === Environment output
  14. handler = module():: Handler module.
  15. handler_opts = any():: Handler options.
  16. == Types
  17. === bindings() = [{atom(), binary()}]
  18. List of bindings found during routing.
  19. === dispatch_rules() - opaque to the user
  20. Rules for dispatching request used by Cowboy.
  21. === routes() = [{Host, Paths} | {Host, cowboy:fields(), Paths}]
  22. With types:
  23. * Host = Path = '_' | iodata()
  24. * Paths = [{Path, Handler, Opts} | {Path, cowboy:fields(), Handler, HandlerOpts}]
  25. * Handler = module()
  26. * HandlerOpts = any()
  27. Human readable list of routes mapping hosts and paths to handlers.
  28. The syntax for routes is defined in the user guide.
  29. === tokens() = [binary()]
  30. List of host_info and path_info tokens found during routing.
  31. == Exports
  32. === compile(routes()) -> dispatch_rules()
  33. Compile the routes for use by Cowboy.