Add support for GET params in POST requests
This commit is contained in:
parent
78a80e6c82
commit
838c0c93ba
1
NEWS.md
1
NEWS.md
@ -5,6 +5,7 @@
|
||||
* Fix windowing with CTE
|
||||
* Retain UTC offset in JSON date output
|
||||
* Set max-age=0 in Cache-Control when using no-cache
|
||||
* Add support for GET params in POST requests
|
||||
|
||||
1.4.0
|
||||
-----
|
||||
|
@ -103,18 +103,19 @@ function handleQuery(req, res) {
|
||||
|
||||
// extract input
|
||||
var body = (req.body) ? req.body : {};
|
||||
var sql = req.query.q || body.q; // HTTP GET and POST store in different vars
|
||||
var api_key = req.query.api_key || body.api_key;
|
||||
_.extend(req.query, body);
|
||||
var sql = req.query.q;
|
||||
var api_key = req.query.api_key;
|
||||
var database = req.query.database; // TODO: Deprecate
|
||||
var limit = parseInt(req.query.rows_per_page);
|
||||
var offset = parseInt(req.query.page);
|
||||
var requestedFormat = req.query.format || body.format;
|
||||
var requestedFormat = req.query.format;
|
||||
var format = _.isArray(requestedFormat) ? _.last(requestedFormat) : requestedFormat;
|
||||
var requestedFilename = req.query.filename || body.filename
|
||||
var requestedFilename = req.query.filename;
|
||||
var filename = requestedFilename;
|
||||
var requestedSkipfields = req.query.skipfields || body.skipfields;
|
||||
var requestedSkipfields = req.query.skipfields;
|
||||
var skipfields;
|
||||
var dp = req.query.dp || body.dp; // decimal point digits (defaults to 6)
|
||||
var dp = req.query.dp; // decimal point digits (defaults to 6)
|
||||
var gn = "the_geom"; // TODO: read from configuration file
|
||||
var user_id;
|
||||
var tableCacheItem;
|
||||
@ -130,6 +131,7 @@ function handleQuery(req, res) {
|
||||
database = (database === "" || _.isUndefined(database)) ? null : database;
|
||||
limit = (!_.isNaN(limit)) ? limit : null;
|
||||
offset = (!_.isNaN(offset)) ? offset * limit : null;
|
||||
console.log("offset", offset);
|
||||
|
||||
// Accept both comma-separated string or array of comma-separated strings
|
||||
if ( requestedSkipfields ) {
|
||||
|
@ -978,4 +978,44 @@ test('GET /api/v1/sql with SQL parameter on SELECT only should return CORS heade
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
test("rows_per_page limit the number of results with get",
|
||||
function(done){
|
||||
assert.response(app, {
|
||||
url: '/api/v1/sql?' + querystring.stringify({
|
||||
q: 'selECT cartodb_id*3 FROM untitle_table_4 limit 10',
|
||||
api_key: '1234',
|
||||
rows_per_page: 2,
|
||||
page: 0
|
||||
}),
|
||||
headers: {host: 'vizzuality.cartodb.com'},
|
||||
method: 'GET'
|
||||
},{ }, function(res) {
|
||||
assert.equal(res.statusCode, 200, res.body);
|
||||
var parsed = JSON.parse(res.body);
|
||||
assert.equal(parsed.rows.length, 2);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
test("rows_per_page limit the number of results with post",
|
||||
function(done){
|
||||
assert.response(app, {
|
||||
url: '/api/v1/sql',
|
||||
data: querystring.stringify({
|
||||
q: 'selECT cartodb_id*3 FROM untitle_table_4 limit 10',
|
||||
api_key: '1234',
|
||||
rows_per_page: 2,
|
||||
page: 0
|
||||
}),
|
||||
headers: {host: 'vizzuality.cartodb.com', 'Content-Type': 'application/x-www-form-urlencoded' },
|
||||
method: 'POST'
|
||||
},{ }, function(res) {
|
||||
assert.equal(res.statusCode, 200, res.body);
|
||||
var parsed = JSON.parse(res.body);
|
||||
assert.equal(parsed.rows.length, 2);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user