Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Latest package versions on Hackage as JSONP

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 example
Octocat-spinner-32 src
Octocat-spinner-32 test
Octocat-spinner-32 .ghci
Octocat-spinner-32 .gitignore
Octocat-spinner-32 .travis.yml
Octocat-spinner-32 LICENSE
Octocat-spinner-32 README.markdown
Octocat-spinner-32 Setup.lhs
Octocat-spinner-32 hackage-jsonp.cabal
README.markdown

About

Parse the Hackage upload log and write the latest version of each package into a JSON/JSONP file.

Up-to-date versions of both JSON and JSONP are repeatedly generated at http://www.typeful.net/~tbot/hackage/. The JSONP callback is hard-coded to hackagePackageVersionsCallback.

Examples

Haskell (aeson/syb)

import           Data.Maybe
import qualified Data.Map as Map
import           Network.URI
import           Network.HTTP
import           Data.Aeson.Generic

url :: String
url = "http://www.typeful.net/~tbot/hackage/latest-package-versions.json"

-- | Return latest version of a package.
--
-- >>> getVersion "hspec"
-- Just "0.9.2"
getVersion :: String -> IO (Maybe String)
getVersion name = do
  r <- simpleHTTP request >>= getResponseBody
  return (decode r >>= Map.lookup name)
  where
    request = (mkRequest GET . fromJust . parseURI) url

HTML/JavaScript

JSONP allows a javascript client to relax the same origin policy and retrieve the above JSON by providing the callback function hackagePackageVersionsCallback.

index.html

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>Example</title>
  </head>
  <body>
    <p>
      The latest version of hspec is <span id="result">???</span>.
    </p>
    <script src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
    <script src="custom.js"></script>
  </body>
</html>

custom.js

$(document).ready(function() {

  /* fetch latest packages versions, the result will be passed to
   * hackagePackageVersionsCallback(..) */
  $.getScript("http://www.typeful.net/~tbot/hackage/latest-package-versions.jsonp");
});

function hackagePackageVersionsCallback(response) {

  /* output latest version of hspec */
  var version = $(response).attr("hspec");
  $("#result").text(version);
}
Something went wrong with that request. Please try again.