Skip to content
Browse files

Add status tab with request info

  • Loading branch information...
1 parent cdfb20c commit 67b95f7c28fb069ee659320973bc0d5d97c3f5aa @dxg dxg committed Nov 28, 2012
View
21 app/assets/javascripts/api_taster/app.js
@@ -35,6 +35,12 @@ var ApiTaster = {
}
return detectedContentType;
+ },
+
+ fillInInfoTab: function($tab, xhr) {
+ $tab.find('.status td.value').text(xhr.status + " " + xhr.statusText);
+ $tab.find('.headers td.value').text(xhr.getAllResponseHeaders());
+ $tab.find('.time td.value').text((ApiTaster.endTime - ApiTaster.startTime) + " ms");
}
};
@@ -120,15 +126,28 @@ jQuery(function($) {
});
});
+ // These callbacks are a few ms more accurate than click/submit above/below
+ $("form").bind("ajax:beforeSend", function() {
+ ApiTaster.startTime = Date.now();
+ });
+ $("form").bind("ajax:success", function() {
+ ApiTaster.endTime = Date.now();
+ });
+
$("form").bind("ajax:complete", function(e, xhr, status) {
- ApiTaster.enableSubmitButton();
+ ApiTaster.enableSubmitButton();
ApiTaster.enableUrlParams();
ApiTaster.restoreFormActionFor(this);
if ($("#show-api-response-div:visible").length == 0) {
$("#show-api-response-div").slideDown(100);
}
+ ApiTaster.fillInInfoTab(
+ $("#show-api-response-div").showNavTab("info"),
+ xhr
+ );
+
switch (ApiTaster.detectContentType(xhr)) {
case "json":
$("#show-api-response-div").showNavTab("json").text(
View
17 app/assets/stylesheets/api_taster/layout.css.scss
@@ -85,9 +85,26 @@ legend {
}
#show-api-response-div {
+ pre {
+ color: #fff;
+ }
pre.nowrap {
overflow-x: auto;
white-space: pre;
word-wrap: normal;
}
+ pre[ref=response-info] {
+ background: #000;
+ }
+
+ table {
+ td {
+ padding: 0 1em 0 0;
+ vertical-align: top;
+
+ &.name {
+ text-align: right;
+ }
+ }
+ }
}
View
17 app/views/api_taster/routes/show.html.erb
@@ -59,9 +59,26 @@
<div id="show-api-response-div" class="well hidden">
<ul class="nav nav-tabs">
<li class="nav-label">Response</li>
+ <li class="hidden"><a href="#" id="response-info">Info</a></li>
<li class="hidden"><a href="#" id="response-json">JSON</a></li>
<li class="active"><a href="#" id="response-raw">Raw</a></li>
</ul>
+ <pre ref="response-info">
+ <table>
+ <tr class="status">
+ <td class="name">HTTP_status:</td>
+ <td class="value str"></td>
+ </tr>
+ <tr class="time">
+ <td class="name">Time:</td>
+ <td class="value str"></td>
+ </tr>
+ <tr class="headers">
+ <td class="name">Headers:</td>
+ <td class="value str"></td>
+ </tr>
+ </table>
+ </pre>
<pre class="prettyprint nowrap hidden" ref="response-json"></pre>
<pre class="prettyprint" ref="response-raw"></pre>
</div>

0 comments on commit 67b95f7

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