Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #1 from dgc-wh/add-json-schema-validation

Accept Request Content
  • Loading branch information...
commit 241e09e87443f1fce50454c6edb36db445667158 2 parents 084d5f1 + cb5bb84
@whump authored
Showing with 79 additions and 16 deletions.
  1. +9 −2 README.md
  2. +30 −13 app.js
  3. +22 −0 public/stylesheets/style.css
  4. +18 −1 views/api.jade
View
11 README.md
@@ -379,6 +379,11 @@ You should look at the *./public/data/* directory for examples.
"sugarbombs",
"frostedteeth"
],
+ "EnumeratedDescription": {
+ "fruitscoops": "Fruit Scoops (packed with fruit goodness)",
+ "sugarbombs": "Sugar Bombs (filled with sugar)",
+ "frostedteeth": "Frosted Teeth (sugar coating)"
+ },
"Description":"The type of cereal desired"
},
{
@@ -425,9 +430,11 @@ Line:
24. "EnumeratedList" key value is an array of enumerated values that will render a drop-down (select box) on the form.
-25. Each value in the list is a string.
+25. "EnumeratedDescription" key value is an object of enumerated values as keys, and their descriptions as values that will be displayed below the Description.
-35. "Type" key value is *boolean* that will render a drop-down (select box) on the form for *true* and *false*.
+26. Each value in the list is a string.
+
+27. "Type" key value is *boolean* that will render a drop-down (select box) on the form for *true* and *false*.
SUPPORT
=======
View
43 app.js
@@ -316,6 +316,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,
@@ -507,6 +509,8 @@ function processRequest(req, res, next) {
function unsecuredCall() {
console.log('Unsecured Call');
+ options.path += ((paramString.length > 0) ? '?' + paramString : "");
+
// Add API Key to params, if any.
if (apiKey != '' && apiKey != 'undefined' && apiKey != undefined) {
if (options.path.indexOf('?') !== -1) {
@@ -553,10 +557,11 @@ function processRequest(req, res, next) {
options.headers = headers;
}
- if (!options.headers['Content-Length']) {
- options.headers['Content-Length'] = 0;
+ if (content.length > 0) {
+ options.headers['Content-Length'] = content.length;
}
+
if (config.debug) {
console.log(util.inspect(options));
};
@@ -570,10 +575,17 @@ 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) {
response.setEncoding('utf-8');
+
if (config.debug) {
console.log('HEADERS: ' + JSON.stringify(response.headers));
console.log('STATUS CODE: ' + response.statusCode);
@@ -623,27 +635,31 @@ function processRequest(req, res, next) {
};
});
+ if(content !== ''){
+ apiCall.write(content,'utf-8');
+ }
apiCall.end();
}
}
+
// Dynamic Helpers
// Passes variables to the view
app.dynamicHelpers({
session: function(req, res) {
// If api wasn't passed in as a parameter, check the path to see if it's there
- if (!req.params.api) {
- pathName = req.url.replace('/','');
- // Is it a valid API - if there's a config file we can assume so
- fs.stat('public/data/' + pathName + '.json', function (error, stats) {
- if (stats) {
- req.params.api = pathName;
- }
- });
- }
- // If the cookie says we're authed for this particular API, set the session to authed as well
+ if (!req.params.api) {
+ pathName = req.url.replace('/','');
+ // Is it a valid API - if there's a config file we can assume so
+ fs.stat('public/data/' + pathName + '.json', function (error, stats) {
+ if (stats) {
+ req.params.api = pathName;
+ }
+ });
+ }
+ // If the cookie says we're authed for this particular API, set the session to authed as well
if (req.params.api && req.session[req.params.api] && req.session[req.params.api]['authed']) {
- req.session['authed'] = true;
+ req.session['authed'] = true;
}
return req.session;
@@ -668,6 +684,7 @@ app.dynamicHelpers({
}
})
+
//
// Routes
//
View
22 public/stylesheets/style.css
@@ -737,6 +737,28 @@ li {
zoom: 1;
}
+dl {
+ display: block;
+ margin-bottom: 10px;
+ font-weight: normal;
+}
+dt {
+ width: 30%;
+ border-top: 1px rgba(0,0,0,.2) solid;
+ padding-top: 5px;
+ margin-top: 5px;
+ display: block;
+ float: left;
+}
+dd {
+ width: 70%;
+ border-top: 1px rgba(0,0,0,.2) solid;
+ padding-top: 5px;
+ margin-top: 5px;
+ display: block;
+ float: left;
+}
+
@media print {
* {
background: transparent !important;
View
19 views/api.jade
@@ -120,7 +120,13 @@ ul
- else
input(name='params[' + parameter.Name + ']', value=parameter.Default, placeholder=className)
td.type=parameter.Type
- td.description=parameter.Description || 'No description'
+ td.description
+ p=parameter.Description || 'No description'
+ - if (parameter.Type =='enumerated' && parameter.EnumeratedDescription)
+ dl.clearfix
+ - each description, choice in parameter.EnumeratedDescription
+ dt #{choice}
+ dd #{description}
- if (method.headers && method.headers.length > 0)
div.headers
h4.title
@@ -146,5 +152,16 @@ 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)
+ 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'])
input(type='submit', id=method.MethodName, value='Try it!')
Please sign in to comment.
Something went wrong with that request. Please try again.