Skip to content

qerub/ring-middleware-jsonp

stable
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 

ring.middleware.jsonp

Installation

Add the following to your project.clj :dependencies:

Clojars Project

Usage

Wrap your Ring application with wrap-json-with-padding and JSON resources will automatically support JSONP.

Example:

(use 'ring.middleware.jsonp 'ring.util.response)

(def app
  (-> (response "{\"result\": 42}")
      (content-type "application/json")
      (constantly)
      (wrap-json-with-padding))) ; <--

(:body (app {}))
; => "{\"result\": 42}"

(:body (app {:params {:callback "f"}}))
; => "f({\"result\": 42});"

Compojure

If you're using Compojure, make sure wrap-json-with-padding is placed above your site handler (if you have one).

Example:

(def app
  (-> app-routes
      (wrap-json-with-padding) ; <--
      (handler/site)
      ...))

License

Copyright (C) 2012–2014 Christoffer Sawicki, Gary Fredericks, Markus Hjort

Distributed under the Eclipse Public License, the same as Clojure.

About

[Clojure] Ring middleware for JSONP

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •