-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
71 lines (64 loc) · 2.27 KB
/
index.html
File metadata and controls
71 lines (64 loc) · 2.27 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
<!doctype html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>Testing Cucumber Json Api Step Definitions</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<h3>superagent</h3>
<pre id="superagent-header">
{ "text": "wating for a header from the backend .." }
</pre>
<pre id="superagent">
{ "text": "Hello Fill me with some API Data" }
</pre>
<input onClick="sendSuperagent()" id="superagent_button" type="button" value="superagent"/>
<h3>reqwest</h3>
<pre id="reqwest">
{ "text": "Hello Fill me with some API Data" }
</pre>
<input onClick="sendReqwest()" id="reqwest_button" type="button" value="reqwest"/>
<script>
sendSuperagent = function() {
req = superagent.post("http://localhost:8000/api/auth")
.set('Accept', 'application/json').send(
{
name: "admin",
password: "password"
}
).end(
function(error, response) {
if (response && response.body) {
document.getElementById('superagent').textContent = JSON.stringify(response.body, null, 2);
document.getElementById('superagent-header').textContent = JSON.stringify(
response.header, null, 2);
} else {
document.getElementById('superagent').textContent = `{"text": "An error occured"}`
}
});
};
sendReqwest = function() {
reqwest({
url: "http://localhost:8000/api/posts",
method: "post",
data: JSON.stringify({
title: "newest blog Post",
body: "long opinionated speach about smth. related to Development",
tags: "it, programming, zeitgeist",
author: "author"
}),
success: function (resp) {
document.getElementById('reqwest').textContent = JSON.stringify(resp, null, 2);
},
error: function (err) {
document.getElementById('reqwest').textContent = '{ "text": "an error occured"}';
}
});
};
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/reqwest/2.0.5/reqwest.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/superagent/1.2.0/superagent.min.js"></script>
</body>
</html>