Connector Map
Pedestal provides functions to create a connector.
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.
Pedestal connectors were added in 0.8.0 as a replacement for the service map and the
io.pedestal.http namespace.
|
Connector Map Keys
An initial connector map can be created by 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" |
:router |
Keyword or fn |
Routing constructor to use, default is :sawtooth |
: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. |
Default interceptors
The with-default-interceptors
function is used to add interceptors to the service map for
common functionality. It is passed the connector 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)
|
Routing
The with-routes
macro is used to set the routes for your service.
It is a macro because it sets up a REPL-friendly
workflow (when in development mode) --- in development mode,
code changes will be reflected immediately, without restarting the application.
Creating the Pedestal connector
The connector map is passed to a Pedestal connector factory function, along with a map of configuration
specific to the specific factor, and returns a
PedestalConnector
object, which can be started with start!
.
Factory functions:
-
create-connector
(Jetty) -
create-connector
(Http-Kit)
Development Mode
Functions in the
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 optionally-with-dev-mode-interceptors
function adds useful development-time interceptors,
but only if Development Mode is enabled.