Getting a forum with id's works
This commit is contained in:
@@ -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>
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user