Pedestal provides functions to create a connector.adoc.
The service map contains general information that any Pedestal connector will need to create a network connector. This is supplemented by a connector-specific configuration map.
An initial service map can be created by api:default-connector-map[].
Key | Type | Description |
---|---|---|
:port | Number | Port for the network connector to receive connections on |
:host | String | Hostname to listen on, defaults to "localhost" |
:interceptors | Vector | Interceptor to used when processing requests. |
:initial-context | Map | Initial context that will be used when executing the interceptor chain |
:join? | Boolean | If true (the default is false) then the current thread will block when the connector is started. |
The created Pedestal connector will often prefix the supplied interceptors with ones specific to the connector.
Supplying an :initial-context is a way to provide useful data, functions, or components to all interceptors and handlers. |
The api:with-default-interceptors[] function is used to add interceptors to the service map for much common functionality. It is passed the service map and an additional configuration map and will add interceptors for the following functionality:
Request tracing
Request logging
Allowed origins
Session support
Cross site request forgery detection
Default content type for responses
Parsing of query parameters
Secure headers (adds a few headers to improve security)
|
If the value for ::http/secure-headers is present, it may contain keys and string values for the security headers. Any other keys will be ignored.
The api:with-file-access[] and api:with-resource-access[] functions add interceptors that will expose file system or class path resources to the client; this is an alternative to exposing files and resources via routes.
The api:with-routing[] macro is used to add a router and routes to your service. It is a macro because it sets up a REPL-friendly workflow (when in development mode).
The service map is passed to a Pedestal connector factory function, along with a map of configuration specific to the Pedestal connector, and returns a api:PedestalConnector[ns=io.pedestal.service.protocols] object, which can be started with api:start![].
Factory functions:
api:create-connector[ns=io.pedestal.http.jetty] (Jetty)
api:create-connector[ns=io.pedestal.http.http-kit] (Http-Kit)
Additional functions in the api:*[ns=io.pedestal.connector.dev] namespace provide additional support that may be used when developing and testing locally, but should not be used in production.
The service map can grow quite complex, with options controlling everything from routing, to security, to container-specific options.
The service map may be validated via {clojure_spec}; this involves loading the appropriate spec namespaces and using Clojure’s built-in instrumention and testing support.
Can you improve this documentation?Edit on GitHub
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close