Jakob Voß > Plack-Middleware-JSONP-Headers-0.1 > Plack::Middleware::JSONP::Headers

Download:
Plack-Middleware-JSONP-Headers-0.1.tar.gz

Dependencies

Annotate this POD

Website

View/Report Bugs
Module Version: 0.1   Source   Latest Release: Plack-Middleware-JSONP-Headers-0.11

NAME ^

Plack::Middleware::JSONP::Headers - Wraps JSON response with HTTP headers in JSONP

VERSION ^

version 0.1

SYNOPSIS ^

    enable "JSONP::Headers", 
                callback_key => 'jsonp',
                headers          => qr/^(X-|Link$)/;

DESCRIPTION ^

Plack::Middleware::JSONP::Headers wraps JSON response in JSONP (just like Plack::Middleware::JSONP) and adds HTTP header information. For instance the JSON response

    { "foo": "bar" }

with query parameter callback set to doz is wrapped to

    doz({ 
      "meta": { 
            "status": 200, 
                "Content-Type": "application/javascript"
          }, 
          "data": { "foo": "bar" }
    })

The HTTP headers to be wrapped can be configured. All header values are returned as strings (repeatable headers are ignored) with one exception: Link-headers are parsed and returned as array of <[ url, options ]> tuples.

Same as Plack::Middleware::JSONP this middleware only works with a non-streaming response.

CONFIGURATION ^

callback_key

Callback query parameter. Set to callback by default.

headers

List of HTTP headers or regular expression of headers to add to the response. One can alternatively pass a code reference that gets each header as key-value pair. By default all headers are wrapped.

SEE ALSO ^

Inspired by http://developer.github.com/v3/#json-p-callbacks.

AUTHOR ^

Jakob Voß <voss@gbv.de>

COPYRIGHT AND LICENSE ^

This software is copyright (c) 2012 by Jakob Voß.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.

syntax highlighting: