-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathmy_rest_gui.html
78 lines (70 loc) · 2.71 KB
/
my_rest_gui.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.4/css/bootstrap.min.css" rel="stylesheet"
media="screen">
<title>Test REST Service</title>
</head>
<body>
<div class="container">
<h1>Rest service tester</h1>
<h2>You need <a href="../common/login">admin</a> grants to call Rest Service</h2>
<hr>
This is a simple web interface for testing a custom REST service controller <strong>\controllers\MyRest.php</strong>
which extends <a href="examples/about/example/rest_service"><strong>framework\RestService</strong></a> class <br>
<hr>
To create PUT,GET,POST and DELETE rest service simple create a new controller by extending <strong>framework\RestService</strong>
by overriding the following methods <br><br><br>
<blockquote>
public function httpGetRequest($method, $args)
</blockquote>
<blockquote>
public function httpPostRequest($method, $args)
</blockquote>
<blockquote>
public function httpPutRequest($method, $args)
</blockquote>
<blockquote>
public function httpDeleteRequest($method, $args)
</blockquote>
<hr>
GET requests:
<ul>
<li><a href="my_rest/part/02"> my_rest/part/02</a></li>
<li><a href="my_rest/category/02"> my_rest/category/02</a></li>
</ul>
POST request:
<form class="form-inline">
<select id="method" class="form-control">
<option value="part">part</option>
<option value="category">category</option>
</select>
<select id="arg" class="form-control">
<option value="01">01</option>
<option value="02">02</option>
</select>
<a id="send" class="btn btn-primary" onclick="submitFormAjax()">Send POST request to service</a>
</form>
<hr>
<a href="examples/about/example/myrest" class="btn btn-info">Show source code</a>
<a href="examples/" class="btn btn-primary">Examples TOC</a>
</div>
<script>
function submitFormAjax() {
let xmlhttp= window.XMLHttpRequest ?
new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
xmlhttp.onreadystatechange = function() {
if (this.readyState === 4 && this.status === 200)
alert(this.responseText); // Here is the response
}
let method = document.getElementById('method').value;
let arg = document.getElementById('arg').value;
xmlhttp.open("POST","my_rest/"+ method +"/" + arg,true);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlhttp.send();
}
</script>
</body>
</html>