Skip to content

Comment on How to create a self hosted API for development and testing

Comments

You can allow non-administrator access using netsh[1] as an administrator. That way you don't need to run VS as admin.

    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...

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.