Skip to content

Added basic support for array query parameters #61

Closed
wants to merge 4 commits into from
View
4 app.js
@@ -28,7 +28,7 @@ var express = require('express'),
util = require('util'),
fs = require('fs'),
OAuth = require('oauth').OAuth,
- query = require('querystring'),
+ query = require('qs'),
url = require('url'),
http = require('http'),
https = require('https'),
@@ -309,7 +309,7 @@ function processRequest(req, res, next) {
// If the param is actually a part of the URL, put it in the URL and remove the param
if (!!regx.test(methodURL)) {
- methodURL = methodURL.replace(regx, params[param]);
+ methodURL = methodURL.replace(regx, encodeURIComponent(params[param]));
delete params[param]
}
} else {
View
2 package.json
@@ -26,7 +26,7 @@
"jade": "0.13",
"oauth": "0.9.3",
"redis": ">= 0.7.0",
- "querystring": "0.1.0"
+ "qs": ">= 0.5.3"
},
"devDependencies": {},
"main": "index",
View
7 public/data/apiconfig.json
@@ -1,4 +1,11 @@
{
+ "arrayparamdemo": {
+ "name": "Stou array param demo",
+ "protocol": "http",
+ "baseURL": "localhost",
+ "publicPath": "/1",
+ "headers" : {}
+ },
"klout": {
"name": "Klout API",
"protocol": "http",
View
23 public/data/arrayparamdemo.json
@@ -0,0 +1,23 @@
+{
+ "endpoints":[
+ {
+ "name":"MyDemo",
+ "methods":[
+ {
+ "MethodName":"MyMethod",
+ "Synopsis":"Demonstrates how to specify parameter of array type",
+ "HTTPMethod":"GET",
+ "URI":"/my-method",
+ "RequiresOAuth":"N",
+ "parameters":[
+ {
+ "Name":"myArrayParam",
+ "Type":"array",
+ "Description":"Array of values"
+ }
+ ]
+ }
+ ]
+ }
+ ]
+}
View
8 public/javascripts/docs.js
@@ -1,5 +1,11 @@
(function() {
+ // Add entry to html array type
+ $('td.parameter > input.add-array-entry').click(function() {
+ $(this).prev().clone().val("").insertBefore(this);
+ })
+
+
// Storing common selections
var allEndpoints = $('li.endpoint'),
allEndpointsLength = allEndpoints.length,
@@ -233,7 +239,7 @@
.addClass('response prettyprint'));
}
- console.log(params);
+ // console.log(params);
$.post('/processReq', params, function(result, text) {
// If we get passed a signin property, open a window to allow the user to signin/link their account
View
3 views/api.jade
@@ -109,6 +109,9 @@ ul
option(value=choice, selected=true) #{choice}
- else
option(value=choice) #{choice}
+ - else if (parameter.Type =='array')
+ input.array-entry(name='params[' + parameter.Name + ']', value=parameter.Default, placeholder=className, style="float: left; clear: both;")
+ input.add-array-entry(type='button', value='Add entry', name=parameter.Name)
- else if (parameter.Type =='boolean')
select(name='params[' + parameter.Name + ']', placeholder=className)
- if (parameter.Default =='')
Something went wrong with that request. Please try again.