Question

I am new with ASP.NET Web API and have been researching this for some time now. Admittedly, I have decision paralysis. I want to make a REST-like API for a system with about 250 tables in the database. It's basically a 2 tier system with a UI and a data access layer, not using business objects or ORM.

I cannot decide if my Web API Controllers should accept/return:

a) IDictionary of name/value pairs, which I would package into sql parameters and pass to the data access layer and return a serialized ado.net data table

b) strongly typed complex object (POCO objects). For example: Account class with all properties matching up with fields in the database.

If I have to create POCO classes for every table in the system, there would be 250+ classes that essentially do nothing except package the data and pass it to our data access layer.

Further, it seems as if I need to create an ApiController for basically every table in the database that I want to expose via the Web Api because you only have GET, POST, PUT, DELETE per route? Please help, banging head on desk.

Was it helpful?

Solution

Please see answers below:

1.**Using **"IDictionary of name/value pairs" is fine if your resource supports GET methods only. If you want users to post or update data, how will you validate the data? In addition, if you want to add HATEOAS, how would you do that? In terms of extension, how would you support nested object hierarchy like the one below:

public class Product 
{
    public int Id { get; set; }
    public string Name { get; set; }

    public string Category { get; set; }

    public decimal Price { get; set; }

    public IList<PurchaseDetail> PurchaseHistory { get; set; }
}

public class PurchaseDetail
{
    public int Id { get; set; }

    public DateTime PurchaseDate { get; set; }

    public decimal Cost { get; set; }
}

2. You can have more than one GET, POST,etc per resources by defining different routes. More from this link http://www.asp.net/web-api/overview/web-api-routing-and-actions/routing-in-aspnet-web-api

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top