Playing JSONP : A basic example to integrate JSONP mechanism in Play Application with the h...

Datetime:2016-08-22 23:48:24          Topic: JSONP           Share

Playing JSONP

Basic example to integrate JSONP mechanism in Play Application with the help of play-jsonp-filter module

play-jsonp-filter

This filter enables JSONP on your existing API: any resource that returns a JSON content will return a JavaScript fragment if there is an additional callback parameter in the query string.

For example, if the resource /foo gives the following JSON result: {"foo": "bar"} , the resource /foo?callback=f will give the following JavaScript result: f({"foo": "bar"}); .

  • Used play-jsonp-filter module to integrate JSONP mechanism
  • Embedded JS & CSS libraries with WebJars .
  • Integrating with a CSS framework (Twitter Bootstrap)
  • Bootswatch-Readable with Twitter Bootstrap to improve the look and feel of the application

Dependency

The play-jsonp-filter module is distributed using Maven Central so it can be easily added as a library dependency in your Play Application’s SBT build scripts, as follows:

"org.julienrf"      %% "play-jsonp-filter"      % "1.2"

Usage

Add the julienrf.play.jsonp.Jsonp filter to your Global object:

import play.api.mvc.WithFilters
import play.api.libs.concurrent.Execution.Implicits.defaultContext
import julienrf.play.jsonp.Jsonp

object Global extends WithFilters(new Jsonp)

Build Instructions

  • To run the Play Framework, you need JDK 6 or later
  • Install Typesafe Activator if you do not have it already. You can get it from here
  • Execute ./activator clean compile to build the product
  • Execute ./activator run to execute the product
  • playing-jsonp should now be accessible at localhost:9000

References

About Anand Kumar Singh

Software Consultant at Knoldus Software LLP. He is having 3+ years of experience in Java, Grails/Groovy and Scala language. Anand also knows about Javascript, jQuery, CSS and other UI design technologies. He is SCJP and OCA certified developer. Anand is passionate to work with upcoming technologies and bleeding platforms providing the new way to programming & development. He is actively involved in development & maintenance of several software projects. He has been enjoying Scala for more than a year now. Anand completed his MCA from IGNOU. As a Developer, Anand is continuing his journey by actively collaborating with other Developers in his field. Anand is actively contributing on the ScalaGeek platform. He likes to spend his free time in Cooking, watching Discovery for new Technology and visiting new places with friends.

View all posts by Anand Kumar Singh





About List