Skip to content

Commit

Permalink
Add http source "formData"
Browse files Browse the repository at this point in the history
Add "formData" as an alias for "form", to make remoting metadata
close to Swagger.
  • Loading branch information
0ff authored and bajtos committed Jun 13, 2016
1 parent 6cf759a commit 2e4a500
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/http-context.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ HttpContext.prototype.buildArgs = function(method) {
val = ctx.req.body;
break;
case 'form':
case 'formData':
// From the form (body)
val = ctx.req.body && ctx.req.body[name];
break;
Expand Down
1 change: 1 addition & 0 deletions lib/http-invocation.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ HttpInvocation.prototype._processArg = function(req, verb, query, accept) {
req.body = val;
break;
case 'form':
case 'formData':
// From the form (body)
req.body = req.body || {};
req.body[name] = val;
Expand Down
21 changes: 21 additions & 0 deletions test/rest.browser.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,27 @@ describe('strong-remoting-rest', function() {
});
});

it('should allow arguments in the formData', function(done) {
var method = givenSharedStaticMethod(
function bar(a, b, cb) {
cb(null, a + b);
},
{
accepts: [
{ arg: 'b', type: 'number', http: {source: 'formData' } },
{ arg: 'a', type: 'number', http: {source: 'formData' } }
],
returns: { arg: 'n', type: 'number' },
http: { path: '/' }
}
);

objects.invoke(method.name, [1, 2], function(err, n) {
assert.equal(n, 3);
done();
});
});

it('should respond with correct args if returns has multiple args', function(done) {
var method = givenSharedStaticMethod(
function(a, b, cb) {
Expand Down

0 comments on commit 2e4a500

Please sign in to comment.