pub fn route_with_cors<P: AsRef<str>>(
    path: P,
    max_body_bytes: u32,
    handlers: RequestHandlers,
    allow_unknown_fields: bool,
    cors_header: &CorsOrigin
) -> BoxedFilter<(impl Reply,)>
Expand description

Constructs a set of warp filters suitable for use in a JSON-RPC server.

path specifies the exact HTTP path for JSON-RPC requests, e.g. “rpc” will match requests on exactly “/rpc”, and not “/rpc/other”.

max_body_bytes sets an upper limit for the number of bytes in the HTTP request body. For further details, see warp::filters::body::content_length_limit.

handlers is the map of functions to which incoming requests will be dispatched. These are keyed by the JSON-RPC request’s “method”.

If allow_unknown_fields is false, requests with unknown fields will cause the server to respond with an error.

Note that this is a convenience function combining the lower-level functions in filters along with a warp CORS filter which

  • allows any origin or specified origin
  • allows “content-type” as a header
  • allows the method “POST”

For further details, see the docs for the filters functions.