Skip to content
This repository

Added basic support for array query parameters #61

Open
wants to merge 4 commits into from

2 participants

Rasmus Stougaard Neil Mansilla
Rasmus Stougaard

Example of how to specify:

{
"Name":"arrayParam",
"Type":"array",
"Description":"Array of values"
}

Example of resulting query string:

… ?param[0]=first-value&param[1]=second-value

stou added some commits
Rasmus Stougaard stou Basic support for array query parameters
Example of how to specify:

{
  "Name":"arrayParam",
  "Type":"array",
  "Description":"Array of values"
}            

Example of resulting query string:

 … ?param[0]=first-value&param[1]=second-value
d48364b
Rasmus Stougaard stou Removed console log to make IE happy 325da28
Rasmus Stougaard stou Url encoded params in url path b61802a
Rasmus Stougaard

I have also added url encoding of URI placeholders to try to fix issue #61

Neil Mansilla
Owner

Thanks for the pull request. Could you provide a sample config in the public/data directory so that people know how to use this feature?

Neil Mansilla
Owner

Rasmus, I've sparked a discussion over on Google+ about passing arrays in the query string.

https://plus.google.com/117717178917897844920/posts/ZCLLVZb3w7x

I was wondering if you could chime in here (or there on G+). Does your API also accept the following as an unordered array?

http://foo.bar/resource/method?name=neil&name=rasmus

I'd like us to consider covering different permutations of array passing that are out there when an API call is instantiated in I/O Docs. So, the I/O Docs multi-value array interface is the same, however, when a call is made, it could be sent as one of the following (depending on a new array request attribute):

  • ?name=neil&name=rasmus
  • ?name[0]=neil&name[1]=rasmus
  • ?name=neil,rasmus
Rasmus Stougaard
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 4 unique commits by 1 author.

Dec 18, 2012
Rasmus Stougaard stou Basic support for array query parameters
Example of how to specify:

{
  "Name":"arrayParam",
  "Type":"array",
  "Description":"Array of values"
}            

Example of resulting query string:

 … ?param[0]=first-value&param[1]=second-value
d48364b
Rasmus Stougaard stou Removed console log to make IE happy 325da28
Rasmus Stougaard stou Url encoded params in url path b61802a
Jan 02, 2013
Rasmus Stougaard stou Added demo configuration for array parameters 32df364
This page is out of date. Refresh to see the latest.
4 app.js
@@ -28,7 +28,7 @@ var express = require('express'),
28 28 util = require('util'),
29 29 fs = require('fs'),
30 30 OAuth = require('oauth').OAuth,
31   - query = require('querystring'),
  31 + query = require('qs'),
32 32 url = require('url'),
33 33 http = require('http'),
34 34 https = require('https'),
@@ -309,7 +309,7 @@ function processRequest(req, res, next) {
309 309
310 310 // If the param is actually a part of the URL, put it in the URL and remove the param
311 311 if (!!regx.test(methodURL)) {
312   - methodURL = methodURL.replace(regx, params[param]);
  312 + methodURL = methodURL.replace(regx, encodeURIComponent(params[param]));
313 313 delete params[param]
314 314 }
315 315 } else {
2  package.json
@@ -26,7 +26,7 @@
26 26 "jade": "0.13",
27 27 "oauth": "0.9.3",
28 28 "redis": ">= 0.7.0",
29   - "querystring": "0.1.0"
  29 + "qs": ">= 0.5.3"
30 30 },
31 31 "devDependencies": {},
32 32 "main": "index",
7 public/data/apiconfig.json
... ... @@ -1,4 +1,11 @@
1 1 {
  2 + "arrayparamdemo": {
  3 + "name": "Stou array param demo",
  4 + "protocol": "http",
  5 + "baseURL": "localhost",
  6 + "publicPath": "/1",
  7 + "headers" : {}
  8 + },
2 9 "klout": {
3 10 "name": "Klout API",
4 11 "protocol": "http",
23 public/data/arrayparamdemo.json
... ... @@ -0,0 +1,23 @@
  1 +{
  2 + "endpoints":[
  3 + {
  4 + "name":"MyDemo",
  5 + "methods":[
  6 + {
  7 + "MethodName":"MyMethod",
  8 + "Synopsis":"Demonstrates how to specify parameter of array type",
  9 + "HTTPMethod":"GET",
  10 + "URI":"/my-method",
  11 + "RequiresOAuth":"N",
  12 + "parameters":[
  13 + {
  14 + "Name":"myArrayParam",
  15 + "Type":"array",
  16 + "Description":"Array of values"
  17 + }
  18 + ]
  19 + }
  20 + ]
  21 + }
  22 + ]
  23 +}
8 public/javascripts/docs.js
... ... @@ -1,5 +1,11 @@
1 1 (function() {
2 2
  3 + // Add entry to html array type
  4 + $('td.parameter > input.add-array-entry').click(function() {
  5 + $(this).prev().clone().val("").insertBefore(this);
  6 + })
  7 +
  8 +
3 9 // Storing common selections
4 10 var allEndpoints = $('li.endpoint'),
5 11 allEndpointsLength = allEndpoints.length,
@@ -233,7 +239,7 @@
233 239 .addClass('response prettyprint'));
234 240 }
235 241
236   - console.log(params);
  242 + // console.log(params);
237 243
238 244 $.post('/processReq', params, function(result, text) {
239 245 // If we get passed a signin property, open a window to allow the user to signin/link their account
3  views/api.jade
@@ -109,6 +109,9 @@ ul
109 109 option(value=choice, selected=true) #{choice}
110 110 - else
111 111 option(value=choice) #{choice}
  112 + - else if (parameter.Type =='array')
  113 + input.array-entry(name='params[' + parameter.Name + ']', value=parameter.Default, placeholder=className, style="float: left; clear: both;")
  114 + input.add-array-entry(type='button', value='Add entry', name=parameter.Name)
112 115 - else if (parameter.Type =='boolean')
113 116 select(name='params[' + parameter.Name + ']', placeholder=className)
114 117 - if (parameter.Default =='')

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.