case class Jsonp(padding: String, json: JsValue) extends Product with Serializable

JSONP helper.

Example of use, provided the following route definition:

GET  /my-service       Application.myService(callback: String)

The following action definition:

def myService(callback: String) = Action {
  val json = ...
  Ok(Jsonp(callback, json))
}

And the following request:

GET /my-service?callback=foo

The response will have content type “application/javascript” and will look like the following:

foo({...});

Another example, showing how to serve either JSON or JSONP from the same action, according to the presence of a “callback” parameter in the query string:

def myService = Action { implicit request =>
  val json = ...
  request.queryString.get("callback").flatMap(_.headOption) match {
    case Some(callback) => Ok(Jsonp(callback, json))
    case None => Ok(json)
  }
}
Source
Jsonp.scala
Linear Supertypes
Serializable, Product, Equals, AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. Jsonp
  2. Serializable
  3. Product
  4. Equals
  5. AnyRef
  6. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. Protected

Instance Constructors

  1. new Jsonp(padding: String, json: JsValue)

Value Members

  1. val json: JsValue
  2. val padding: String
  3. def productElementNames: Iterator[String]
    Definition Classes
    Product