<!doctype html>
<html lang="en">
  <head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    

    <!-- Bootstrap CSS -->
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
    <link rel="stylesheet" href="<?php echo $this->getPublicUri(); ?>css/style.css<?php echo $this->setFileTimestamp(); ?>">

    <title>Test URL</title>
    
    <style>
	    .loader {display: none;}
    </style>
    
  </head>
  <body class="decorated">

	  
    	
  	<div class="container">
	  	<h1>Test HTTP</h1>
	  	<hr>
	  	
		<form id="api-form">
		<div class="form-group row">
			<label for="url" class="col-sm-2 col-form-label">URL</label>
			<div class="col-sm-10">
			  <input type="text" class="form-control" id="url" value="">
			</div>
		</div>
		<div class="form-group row">
			<label for="url" class="col-sm-2 col-form-label">Params</label>
			<div class="col-sm-10">
			  <input type="text" class="form-control" id="params" value="{}">
			</div>
		</div>
		<div class="form-group row">
			<label for="header" class="col-sm-2 col-form-label">Header</label>
			<div class="col-sm-10">
			  <input type="text" class="form-control" id="header" value='{"api-key":""}'>
			</div>
			</div>
			<div class="clearfix">
				<button type="button" class="btn btn-primary btn-test float-right">Test<span class="loader"> [...]</span></button>
			</div>
			<hr>
			<div class="card">
				<div class="card-body">
					<textarea class="form-control" rows="15" id="output"></textarea>
				</div>
			</div>
		</form>
  	</div>
    	

    <!-- Optional JavaScript -->
    <!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.3.1.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
    
    <script>
	    $(document).ready(function () {
		    
		    $('.btn-test').click(function() {
			    
			    var url = $('#url').val();
			    var params = $.trim($('#params').val());
			    var header = $('#header').val();
			    
			    if (params == '') params = '{}';
			    params = $.parseJSON(params);
			    			    
			    $('.loader').show();
			    $('#output').html('');
			    
				$.ajax({
					dataType: "text",
					url:url,
					data: params,
					headers: $.parseJSON(header),
					method: 'POST',
					success: function(ret) {
						$('.loader').hide();
						
						$('#output').html(ret);
					},
					error: function(XMLHttpRequest, textStatus, errorThrown) {
						$('#output').html('Error: '+textStatus);
						$('.loader').hide();
					}
				});
		    });
		    
	    });
    </script>
    
  </body>
</html>