Liking cljdoc? Tell your friends :D

Upgrading to Pedestal 1.0

Pedestal 1.0 removes what Pedestal 0.8 deprecated.

How to upgrade

  1. Upgrade to the latest 0.8 release (0.8.5), run your tests, and fix each deprecation warning. Each warning names the replacement and links to the deprecations page.

  2. Upgrade every io.pedestal dependency to 1.0, clean your target directory, and run your tests again.

0.8 doesn’t warn about quoted symbols in routes, edn-response, exception-debug, implementations of default-content-type, io.pedestal.http.specs, io.pedestal.http.jetty.container, or the server function of io.pedestal.http.jetty; search your code for these.

What was removed

The deprecations page has the details of each.

RemovedUse instead

The service map API (io.pedestal.http)

A connector; see From the service map to a connector

io.pedestal.test

api:*[ns=io.pedestal.connector.test]; see Testing

The ::http/websockets key, add-endpoint, add-endpoints

A route that ends with api:websocket-interceptor[ns=io.pedestal.service.websocket]

start-event-stream, sse-setup

api:start-stream[ns=io.pedestal.http.sse], called from your own interceptor

Quoted symbols and expressions in routes

A Var (#'hello) or the function; call an expression when the routes are defined

edn-response

The data as the response :body

exception-debug

api:uncaught-exception[ns=io.pedestal.connector.dev]

add-satisfies-constraints?

No replacement

The default-content-type function of WriteableBody

Remove it from your implementations, and set the Content-Type header in your responses

The :insecure-ssl? Jetty option

:sni-host-check?, with the opposite value

The :array-coerce-fn JSON parser option

The :value-fn option of api:custom-json-parser[ns=io.pedestal.http.body-params]

io.pedestal.http.jetty.util

Jetty’s API, for example in a :context-configurator function

servlet-init, servlet-service, servlet-destroy

The ConnectorServlet with api:create-bridge[ns=io.pedestal.connector.servlet]; see war-deployment.adoc

From the service map to a connector

Before (0.8):

(ns myapp.server
  (:require [io.pedestal.http :as http]
            [myapp.service :as service]))

(def service-map
  {::http/routes service/routes
   ::http/type   :jetty
   ::http/port   8080})

(defn start
  []
  (-> service-map http/create-server http/start))

After (1.0):

(ns myapp.server
  (:require [io.pedestal.connector :as conn]
            [io.pedestal.http.jetty :as jetty]
            [myapp.service :as service]))

(defn create-connector
  []
  (-> (conn/default-connector-map 8080)
      (conn/with-default-interceptors)
      (conn/with-routes service/routes)
      (jetty/create-connector nil)))

(defn start
  []
  (conn/start! (create-connector)))

See reference:connector-map.adoc for the options.

api:with-default-interceptors[] doesn’t add anti-forgery (CSRF) or method-param: add api:anti-forgery[ns=io.pedestal.http.csrf] and api:method-param[ns=io.pedestal.http.route] yourself, after the default interceptors, with anti-forgery first.

Differences

  • api:response-for[ns=io.pedestal.connector.test] throws an exception that no interceptor handles, instead of returning a 500.

  • api:with-default-interceptors[] includes body-params; remove it from your routes, or the request fails with "Stream closed".

  • api:response-for[ns=io.pedestal.connector.test] doesn’t lower-case header names: use "content-type".

  • api:with-routes[] takes route specifications; pass a routing table to api:router[ns=io.pedestal.http.route].

  • :secure-headers nil means the default secure headers.

  • The :configure callback of a WebSocket is called for each upgrade request.

  • Jetty options go under :container-options; at the top level they are ignored.

Testing

Before (0.8):

(require '[io.pedestal.http :as http]
         '[io.pedestal.test :refer [response-for]])

(def service-fn (::http/service-fn (http/create-servlet service-map)))

(response-for service-fn :get "/hello")

After (1.0), with a connector that doesn’t need to be started:

(require '[io.pedestal.connector.test :refer [response-for]]
         '[myapp.server :as server])

(response-for (server/create-connector) :get "/hello")

Behavior changes

  • An interceptor without a :name gets one derived from its function; route names don’t change.

  • When writing the response body fails before the response is committed, the client gets a 500, not an empty 200.

  • A function body without a Content-Type gets application/octet-stream (since 0.8.3, #903).

Can you improve this documentation?Edit on GitHub

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
←Move to previous article
→Move to next article
Ctrl+/Jump to the search field
× close