Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Added basic support for array query parameters #61

Closed
wants to merge 4 commits into from

3 participants

Rasmus Stougaard Neil Mansilla phairow
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
phairow
Owner

closing since this is old and cannot be merged as is. array parameters in querystring seem like a valid request and we need to find a solution that works for all serialization techniques.

phairow phairow closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Dec 18, 2012
  1. Rasmus Stougaard

    Basic support for array query parameters

    stou authored
    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
  2. Rasmus Stougaard
  3. Rasmus Stougaard

    Url encoded params in url path

    stou authored
Commits on Jan 2, 2013
  1. Rasmus Stougaard
This page is out of date. Refresh to see the latest.
4 app.js
View
@@ -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 {
2  package.json
View
@@ -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",
7 public/data/apiconfig.json
View
@@ -1,4 +1,11 @@
{
+ "arrayparamdemo": {
+ "name": "Stou array param demo",
+ "protocol": "http",
+ "baseURL": "localhost",
+ "publicPath": "/1",
+ "headers" : {}
+ },
"klout": {
"name": "Klout API",
"protocol": "http",
23 public/data/arrayparamdemo.json
View
@@ -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"
+ }
+ ]
+ }
+ ]
+ }
+ ]
+}
8 public/javascripts/docs.js
View
@@ -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
3  views/api.jade
View
@@ -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.