vreksam/WebApi/index.html

72 lines
2.1 KiB
HTML
Raw Normal View History

2017-06-12 12:46:00 +03:00
<h1>api</h1>
2017-06-12 13:37:48 +03:00
<a href="/api/foorum">foorum</a>
2017-06-12 15:26:34 +03:00
<br/>
2017-06-12 14:43:31 +03:00
<button onclick="getForum(prompt('ForumId: ', '1'))">GetForum</button>
2017-06-12 14:16:38 +03:00
<button onclick="getForums()">GetAllForums</button>
<button onclick="addForum()">AddForum</button>
2017-06-12 15:46:53 +03:00
<button onclick="changeForumTitle(prompt('ForumId: ', '1'), prompt('ForumTitle: ', 'Muudetud'))">ChangeForumTitle</button>
<br/>
2017-06-12 15:26:34 +03:00
<button onclick="searchForumAuthor(prompt('Author: ', 'veeb'))">SearchForumAuthor</button>
2017-06-12 13:37:48 +03:00
<code><pre id="output"></pre></code>
<script>
2017-06-12 14:16:38 +03:00
var out = document.getElementById("output");
2017-06-12 14:43:31 +03:00
function getForum(id) {
fetch("/api/foorum/"+id).then(resp => {
return resp.json();
}).then(data => {
console.log(data);
out.innerText = JSON.stringify(data, null, 2);
});
}
2017-06-12 13:37:48 +03:00
function getForums() {
fetch("/api/foorum").then(resp => {
return resp.json();
}).then(data => {
console.log(data);
out.innerText = JSON.stringify(data, null, 2);
});
}
2017-06-12 14:16:38 +03:00
function addForum() {
var dto = {
Author: "Veebileht",
Body: "Siia tuleb <20>ge pikk sisu mingist asjast",
Description: "Siia kirjeldus",
Title: "Uhiuus postitus"
}
fetch("/api/foorum",
{
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(dto)
});
}
2017-06-12 15:26:34 +03:00
2017-06-12 15:46:53 +03:00
function changeForumTitle(id, title) {
var dto = {
Title: title
}
fetch("/api/foorum/"+id,
{
method: 'PUT',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(dto)
});
}
2017-06-12 15:26:34 +03:00
function searchForumAuthor(author) {
fetch("/api/search?author="+author).then(resp => {
return resp.json();
}).then(data => {
console.log(data);
out.innerText = JSON.stringify(data, null, 2);
});
}
2017-06-12 13:37:48 +03:00
</script>