Get package latest version from packagist.org

208 views Asked by At

I'm trying to get the latest stable version for composer packages from packagist.org, for example https://packagist.org/packages/doctrine/cache.

The best way i found is to get a json response using https://packagist.org/packages/doctrine/cache.json, but since i consume it using javascript i blocked by cross domain restriction.

Any ideas ?

1

There are 1 answers

0
Justin Howard On

The easiest way to get around cross domain restrictions is to set up a server-side proxy for the service on your local domain.

  • ajax request to your-domain.com/packagist-proxy?package=doctrine%2Fcache
  • your server makes a request to https://packagist.org/packages/doctrine/cache.json
  • the server forwards the response to the client

You could make it even easier on yourself by doing the processing for the latest version on your server, then just sending that to the client instead of the whole response.