Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 40 additions & 25 deletions flask_debug_api/templates/debug-api/content.html
Original file line number Diff line number Diff line change
@@ -1,27 +1,42 @@
<!doctype html>
<!DOCTYPE html>
<body>
{{ data }}
{% for method in methods %}
<button class="debug-api" data-debug-api-method="{{ method }}">{{ method }}</button>
{% endfor %}
<br>
<textarea rows="15" cols="70" id="data"></textarea>
<script type="text/javascript">
;[].slice.call(document.querySelectorAll('button.debug-api')).forEach(function(btn){
btn.addEventListener('click', function(){
var method = btn.getAttribute('data-debug-api-method')
var xhr = new XMLHttpRequest()
xhr.open(method, location)
xhr.setRequestHeader('Content-Type', 'application/json')
xhr.onreadystatechange = function(){
if(xhr.readyState == 4){
document.open()
document.write(xhr.responseText)
document.close()
}
}
xhr.send(document.getElementById('data').value)
})
})
</script>
{{ data }}
{% for method in methods %}
<button class="debug-api" data-debug-api-method="{{ method }}">
{{ method }}
</button>
{% endfor %}
<br />
<textarea rows="15" cols="70" id="data"></textarea>
<br />
<br />
<div>Headers (in JSON, except Content-Type: application/json)</div>
<textarea rows="15" cols="70" id="headers"></textarea>
<br />
<script type="text/javascript">
[].slice
.call(document.querySelectorAll("button.debug-api"))
.forEach(function(btn) {
btn.addEventListener("click", function() {
var method = btn.getAttribute("data-debug-api-method");
var xhr = new XMLHttpRequest();
xhr.open(method, location);
xhr.setRequestHeader("Content-Type", "application/json");
const headers = document.getElementById("headers").value
? JSON.parse(document.getElementById("headers").value)
: [];
for (headerName in headers) {
xhr.setRequestHeader(headerName, headers[headerName]);
}
xhr.onreadystatechange = function() {
if (xhr.readyState == 4) {
document.open();
document.write(xhr.responseText);
document.close();
}
};
xhr.send(document.getElementById("data").value);
});
});
</script>
</body>