Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
249 lines (238 sloc) 7.87 KB
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>REST-API Debug Tool</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript" src="js/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="js/jquery.ezCookie.js"></script>
<script type="text/javascript">
function addField(key, value) {
skey = "";
svalue = "";
if(key != null) {
skey = key;
}
if(value != null) {
svalue = value;
}
// Check for next free Number (max. 100)
for(i=0;i<100;i++) {
if(!($("#field_"+i).length > 0)) {
// create Fields
html = "<tr id=\"field_"+i+"\">";
html += " <td>"+(i+1)+"</td>";
html += " <td style=\"text-align:center\">";
html += " <input id=\"field_key_"+i+"\" type=\"text\" value=\""+skey+"\" />";
html += " </td>";
html += " <td>:</td>";
html += " <td style=\"text-align:center\">";
html += " <input id=\"field_value_"+i+"\" type=\"text\" value=\""+svalue+"\" />";
html += " </td>";
html += "</tr>";
$("#fieldbox").append(html);
break;
} else if(i==99) {
alert('Max. 100 fields!');
}
}
}
// Fav. Funtions
function saveFav(name) {
fav = {};
fav.name = name;
fav.url = $("#url").val();
fav.method = $("#method").val();
fav.data = [];
i = 0;
while(($("#field_"+i).length > 0)) {
data = {
key: $("#field_key_"+i).val(),
value : $("#field_value_"+i).val()
};
fav.data.push(data);
i++;
}
if($.cookie('RESTDEBUGFAV') == null) {
// no cookie found, create new
$.setCookie('RESTDEBUGFAV', [fav]);
} else {
// append new data to existing
cur = $.cookie('RESTDEBUGFAV');
cur.push(fav);
$.setCookie('RESTDEBUGFAV', cur);
}
loadFavs();
}
function loadFavs() {
$("#favbox").html('');
//$("#fieldbox").html('');
if($.cookie('RESTDEBUGFAV') != null) {
fav = $.cookie('RESTDEBUGFAV');
for(i = 0; i < fav.length; i++) {
content = "<tr>";
content += "<td style=\"width: 15px\">";
content += (i+1);
content += "</td>";
content += "<td>";
content += "<input id=\"load_fav_"+i+"\" value=\""+fav[i].name+"\" type=\"button\" />";
content += "</td>";
content += "<td>";
content += "<input id=\"del_fav_"+i+"\" value=\"Del\" type=\"button\" />";
content += "</td>";
content += "</tr>";
$("#favbox").append(content);
$("#load_fav_"+i).bind("click", {fava: fav[i]}, function(event) {
$("#fieldbox").html('');
$("#url").val(event.data.fava.url);
$("#method").val(event.data.fava.method);
for(i = 0; i < event.data.fava.data.length; i++) {
addField(event.data.fava.data[i].key, event.data.fava.data[i].value);
}
});
$("#del_fav_"+i).bind("click", {index: i}, function(event) {
cur = $.cookie('RESTDEBUGFAV');
cur.splice(event.data.index, 1);
$.setCookie('RESTDEBUGFAV', cur);
loadFavs();
});
}
}
}
$(document).ready(function() {
loadFavs();
// Pressed Enter?
$("#url").keypress(function (e) {
if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {
$('#doIt').click();
}
});
// Clicked the Button
$("#doIt").click(function() {
$.ajax({
url: $("#url").val(),
type: $("#method").val(),
data: $("#hiddenData").val(),
beforeSend: function(request, settings) {
$("#doIt").attr('disabled', 'disabled');
$("#doIt").val("loading...");
// Generate Field Data
i = 0;
other = '';
while(($("#field_"+i).length > 0)) {
key = $("#field_key_"+i).val();
// only existing keys
if(key != '') {
value = $("#field_value_"+i).val();
if(other == '') {
other = key + "=" + value;
} else {
other = other + "&" + key + "=" + value;
}
}
i++;
}
settings.data = other;
},
complete: function(request, textStatus) {
$("#doIt").val('Send');
$("#doIt").attr('disabled', '');
},
success: function(data) {
$('#output').html(data);
},
error: function(request, textStatus, error) {
$('#output').html('<span style="color:red">'+textStatus+': '+error+'</span>');
}
});
});
$("#addField").click(function() {
addField();
});
$("#resetBtn").click(function() {
i = 0;
while(($("#field_"+i).length > 0)) {
$("#field_"+i).remove();
i++;
}
});
$("#saveFav").click(function() {
var name = prompt("Please enter a name:","Favorit");
if(name != "") {
// Save to favorite
saveFav(name);
} else {
alert("Name must not be blank!");
}
});
});
</script>
</head>
<body>
<h2>REST-API Debug Tool</h2>
<table>
<tbody>
<tr>
<td colspan="2">URL</td>
<td>Method</td>
</tr>
<tr>
<td colspan="2"><input id="url" value="api/status" type="text" style="width: 600px" /></td>
<td>
<select id="method">
<option value="GET" selected="selected">GET</option>
<option value="PUT">PUT</option>
<option value="DELETE">DELETE</option>
<option value="POST">POST</option>
</select>
</td>
</tr>
<tr>
<td style="width: 70px;font-weight: bold">Raw-Output:</td>
<td style="WORD-BREAK:BREAK-ALL; width:400px" id="output">
</td>
<td style="text-align: right">
<input type="button" id="doIt" value="Send" />
</td>
</tr>
<tr>
<td colspan="2">
<table>
<tbody style="width: 550px">
<tr>
<td style="width: 380px; vertical-align: top">
<table>
<thead>
<tr>
<th>#</th>
<th style="width:200px">Key</th>
<th>&nbsp;</th>
<th style="width:200px">Value</th>
</tr>
</thead>
<tbody id="fieldbox">
</tbody>
</table>
</td>
<td style="margin:0px; vertical-align: top">
<input style="margin:0px;padding:0px" id="addField" value="Add field" type="button">
<input style="margin:0px;padding:0px" id="resetBtn" value="Reset" type="button">
<input style="margin:0px;padding:0px" id="saveFav" value="Save Fav." type="button">
<table>
<thead>
<tr>
<th colspan="3">Favorites</th>
</tr>
</thead>
<tbody id="favbox">
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</body>
</html>