diff --git a/doc/api.md b/doc/api.md new file mode 100644 index 000000000..feb53c767 --- /dev/null +++ b/doc/api.md @@ -0,0 +1,14 @@ +# API + +## Create DataPackage.json + +``` +GET /tools/create.json?url=... +``` + +## Validate DataPackage.json + +``` +GET /tools/validate.json?url={path-to-data-package} +``` + diff --git a/package.json b/package.json index 5e726a193..7b2185140 100644 --- a/package.json +++ b/package.json @@ -16,6 +16,8 @@ "csv": "", "underscore": "", "datapackage": "0.3.0", + "datapackage-spec": "git://github.com/okfn/datapackage-spec", + "datapackage-validate": ">=0.2.2", "datapackage-read": "" } , "devDependencies": { diff --git a/routes/index.js b/routes/index.js index 508851e3e..466876738 100644 --- a/routes/index.js +++ b/routes/index.js @@ -7,6 +7,8 @@ var fs = require('fs') , config = require('../lib/config') , tools = require('datapackage') , model = require('../lib/model.js') + , spec = require('datapackage-spec') + , validate = require('datapackage-validate') ; var catalog = new model.Catalog(); @@ -171,23 +173,22 @@ exports.toolsDpCreate = function(req, res) { exports.toolsDpValidateJSON = function(req, res) { // handle base urls as well as full urls - var dpurl = req.query.url.replace(/datapackage.json$/, ''); - var dpurl = dpurl.replace(/\/$/, ''); - dpurl += '/datapackage.json'; - tools.validateUrl(dpurl, function(data) { + var dpurl = spec.parse(req.query.url).dataPackageJsonUrl; + validate.validateUrl(dpurl, function(data) { res.json(data); }); }; exports.toolsDpValidate = function(req, res) { - var url = req.query.url; + var url = spec.parse(req.query.url).dataPackageJsonUrl; if (!url) { res.render('tools/dp/validate.html'); } else { - tools.validateUrl(url, function(data) { + validate.validateUrl(url, function(data) { res.render('tools/dp/validate.html', { url: url, - result: data + result: data, + errorsAsJson: JSON.stringify(data.errors, null, 2) }); }); } diff --git a/views/tools/dp/validate.html b/views/tools/dp/validate.html index 3942344ea..7475b6a64 100644 --- a/views/tools/dp/validate.html +++ b/views/tools/dp/validate.html @@ -10,6 +10,9 @@