Skip to content
Browse files

* added content-type control to the api view form

* attempt to send content in requests for which content has been given
  • Loading branch information...
1 parent 87bb306 commit b64c7c63f549bdd9a987f0a628af410d01d28c26 @dgc-wh dgc-wh committed Aug 11, 2012
Showing with 16 additions and 2 deletions.
  1. +12 −1 app.js
  2. +4 −1 views/api.jade
View
13 app.js
@@ -317,6 +317,8 @@ function processRequest(req, res, next) {
var reqQuery = req.body,
params = reqQuery.params || {},
+ content = reqQuery.requestContent || '',
+ contentType = reqQuery.contentType || '',
methodURL = reqQuery.methodUri,
httpMethod = reqQuery.httpMethod,
apiKey = reqQuery.apiKey,
@@ -330,7 +332,7 @@ function processRequest(req, res, next) {
if (params.hasOwnProperty(param)) {
if (params[param] !== '') {
// URL params are prepended with ":"
- var regx = new RegExp('^:' + param);
+ var regx = new RegExp(':' + param);
// If the param is actually a part of the URL, put it in the URL and remove the param
if (!!regx.test(methodURL)) {
@@ -571,6 +573,12 @@ function processRequest(req, res, next) {
console.log('Protocol: HTTP');
doRequest = http.request;
}
+ if(contentType !== ''){
+ if (config.debug) {
+ console.log('Setting Content-Type: ' + contentType);
+ }
+ options.headers['Content-Type'] = contentType;
+ }
// API Call. response is the response from the API, res is the response we will send back to the user.
var apiCall = doRequest(options, function(response) {
@@ -624,6 +632,9 @@ function processRequest(req, res, next) {
};
});
+ if(content !== ''){
+ apiCall.write(content);
+ }
apiCall.end();
}
}
View
5 views/api.jade
@@ -146,12 +146,15 @@ ul
a(href='#', class='remove') Remove
a(href='#', class='add-headers') Add Header
// Create header fields and button to add/remove headers.
- - if (method.content )
+ - if (method.content)
div.content
h4.title
div.indicator
span Content
div.fields
+ select(name='contentType')
+ - each choice in method.content.contentType
+ option(value=choice) #{choice}
textarea(columns='80', rows='10', name='requestContent', placeholder='{}')
a(href='#', class='remove') Remove
- if (!method['read-only'])

0 comments on commit b64c7c6

Please sign in to comment.
Something went wrong with that request. Please try again.