Getting a forum with id's works

This commit is contained in:
2017-06-12 14:43:31 +03:00
parent 475f0d539c
commit bf9ec07808
7 changed files with 60 additions and 11 deletions

View File

@@ -23,9 +23,14 @@ namespace WebApi.Controllers
}
// GET api/<controller>/5
public string Get(int id)
public IHttpActionResult Get(int id)
{
return "value";
var f = _foorumService.Get(id);
if (f == null)
{
return NotFound();
}
return Ok(f);
}
// POST api/<controller>

View File

@@ -1,5 +1,6 @@
<h1>api</h1>
<a href="/api/foorum">foorum</a>
<button onclick="getForum(prompt('ForumId: ', '1'))">GetForum</button>
<button onclick="getForums()">GetAllForums</button>
<button onclick="addForum()">AddForum</button>
<code><pre id="output"></pre></code>
@@ -7,6 +8,15 @@
<script>
var out = document.getElementById("output");
function getForum(id) {
fetch("/api/foorum/"+id).then(resp => {
return resp.json();
}).then(data => {
console.log(data);
out.innerText = JSON.stringify(data, null, 2);
});
}
function getForums() {
fetch("/api/foorum").then(resp => {
return resp.json();