How to create a self hosted API for development and testing(jeremymorgan.com)
jeremymorgan.com
How to create a self hosted API for development and testing
http://www.jeremymorgan.com/blog/programming/how-to-create-asp-self-hosted-api/
7 comments
You can allow non-administrator access using netsh[1] as an administrator. That way you don't need to run VS as admin.
For the Delete method you can return an HttpStatusCode instead of throwing an exception.
[1] https://github.com/NancyFx/Nancy/wiki/Hosting-nancy-with-owi...
[2] http://www.asp.net/web-api/overview/hosting-aspnet-web-api/u...
netsh http add urlacl url=http://+:8080/ user=DOMAIN\username
You don't need attributes based routing in this example. Convention based routing is built into WebAPI.For the Delete method you can return an HttpStatusCode instead of throwing an exception.
public IHttpActionResult Delete(int Id)
{
var result = (from b in ourbooks
where b.Id == Id
select b).FirstOrDefault();
ourbooks.Remove(result);
return StatusCode(HttpStatusCode.Accepted);
}
Also check out the OWIN self host tutorial [2].[1] https://github.com/NancyFx/Nancy/wiki/Hosting-nancy-with-owi...
[2] http://www.asp.net/web-api/overview/hosting-aspnet-web-api/u...
Is the normal way to returning "success" values (throwing an exception?)
var resp = new HttpResponseMessage(HttpStatusCode.Created);
throw new HttpResponseException(resp);Apiary is also a good option ( http://apiary.io).
i've been using apiary this week and it's been absolutely fantastic so far. Markdown goes in, API docs + mock live API comes out, even syncs with github.
it's definitely a great tool, it's really useful being able to chop and change in the early stages of designing an API without being committed in the code.
Does anyone know of a similar guide for Ruby?
I'm an ASP.net developer and I'm trying to get some insight into other (perhaps quicker/easier) ways of doing exactly what this guide describes.
There was an REST server that responded with just a json you specify for a particular url, but god i can't recall the name.
Tho, http://requestb.in/ is a superb tool as well as https://www.runscope.com if you need more power.
p.s. this one too : http://httpbin.org/
Tho, http://requestb.in/ is a superb tool as well as https://www.runscope.com if you need more power.
p.s. this one too : http://httpbin.org/
excellent! thanks!
-bowerbird
-bowerbird
That's the first time I've heard that meaning of "self hosted." I was expecting something like a REST server that also acted as a client to another instance of itself.
Here's a quick take. I'm sure it can be cleaned up further. I've also taken the liberty of fixing the delete before post id bug.