-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRESTapi_NETPIE.html
More file actions
82 lines (70 loc) · 3.34 KB
/
RESTapi_NETPIE.html
File metadata and controls
82 lines (70 loc) · 3.34 KB
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
79
80
81
82
<script src="https://code.jquery.com/jquery-2.2.3.min.js"></script>
<div>
<h3>DEMO RESTAPI NETPIE</h3>
<table>
<tr><td style="text-align:right;">Application ID</td><td><input type="text" id="appid" style="width:500px;" placeholder="e.g. demorestapi" value=""/></td></tr>
<tr><td style="text-align:right;">Key</td><td><input type="text" style="width:500px;" id="key" placeholder="e.g. suighruiehgurhg" value=""/></td></tr>
<tr><td style="text-align:right;">Secret</td><td><input type="text" style="width:500px;" id="secret" placeholder="e.g. dzhguirhguihruigheruihgu" value=""/></td></tr>
<tr><td style="text-align:right;">Topic</td><td><input type="text" style="width:500px;" id="topic" placeholder="e.g. /channel/message" value="/channel/message"/></td></tr>
<tr><td style="text-align:right;">Message</td><td><input type="text" style="width:500px;" id="msg" placeholder="e.g. hello." value="hello"/></td></tr>
<tr><td style="text-align:right;"></td><td><input type="submit" style="cursor:pointer;" value="Send" onclick="restSend();"/></td></tr>
</table>
</div>
<div id="alink" style="background-color: orange;"></div>
<pre>
<b>Code Javascript</b>
var appid = document.getElementById("appid").value;
var key = document.getElementById("key").value;
var secret = document.getElementById("secret").value;
var channel = document.getElementById("topic").value;
var message = document.getElementById("msg").value;
var url = "https://api.netpie.io/topic/"+appid+channel+"?retain";
if((appid.length)>0 && (key.length)>0 && (secret.length)>0 && (channel.length)>0 && (message.length)>0){
document.getElementById("alink").innerHTML = "Open URL link : <a href='https://api.netpie.io/topic/"+appid+channel+"?auth="+key+":"+secret+"' target='_bank'>https://api.netpie.io/topic/"+appid+channel+"?auth="+key+":"+secret+"</a>";
$.ajax({
type: "PUT",
url: url,
dataType: 'json',
async: true,
headers: {
"Authorization": "Basic " + btoa(key + ":" + secret)
},
data: '{ "'+message+'" }',
success: function (){
alert('Send message success!');
},
err: function (){
alert('Send message fail!');
}
});
}else alert('Please input all field.');
</pre>
<script>
function restSend(){
var appid = document.getElementById("appid").value;
var key = document.getElementById("key").value;
var secret = document.getElementById("secret").value;
var channel = document.getElementById("topic").value;
var message = document.getElementById("msg").value;
var url = "https://api.netpie.io/topic/"+appid+channel+"?retain";
if((appid.length)>0 && (key.length)>0 && (secret.length)>0 && (channel.length)>0 && (message.length)>0){
document.getElementById("alink").innerHTML = "Open URL link : <a href='https://api.netpie.io/topic/"+appid+channel+"?auth="+key+":"+secret+"' target='_bank'>https://api.netpie.io/topic/"+appid+channel+"?auth="+key+":"+secret+"</a>";
$.ajax({
type: "PUT",
url: url,
dataType: 'json',
async: true,
headers: {
"Authorization": "Basic " + btoa(key + ":" + secret)
},
data: '{ "'+message+'" }',
success: function (){
alert('Send message success!');
},
err: function (){
alert('Send message fail!');
}
});
}else alert('Please input all field.');
}
</script>