Last active
January 3, 2016 10:49
-
-
Save lnickers2004/8451799 to your computer and use it in GitHub Desktop.
Web API 2: very basic return of a json array. NOTE: this is not recommended method of generating JSON
we should use a formatter and return IHTTPResult etc. instead. But, this is a quick start at returning a list as a javascript array
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using CountingKs.Data; | |
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Net; | |
using System.Net.Http; | |
using System.Web.Http; | |
namespace CountingKs.Controllers | |
{ | |
public class FoodsController : ApiController | |
{ | |
public object Get() | |
{ | |
var repo = new CountingKsRepository( | |
new CountingKsContext()); | |
var results = repo.GetAllFoods() | |
.OrderBy(f => f.Description) | |
.Take(25) | |
.ToList(); | |
return results; | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ | |
{ | |
"id":4499, | |
"description":"Abalone, Mixed Species, Raw", | |
"measures":[ | |
] | |
}, | |
{ | |
"id":4500, | |
"description":"Abalone, Mxd Sp, Ckd, Fried", | |
"measures":[ | |
] | |
}, | |
{ | |
"id":2498, | |
"description":"Abiyuch, Raw", | |
"measures":[ | |
] | |
}, | |
{ | |
"id":2197, | |
"description":"Acerola Juice, Raw", | |
"measures":[ | |
] | |
}, | |
{ | |
"id":2196, | |
"description":"Acerola, (West Indian Cherry), Raw", | |
"measures":[ | |
] | |
}, | |
{ | |
"id":3652, | |
"description":"Acorn Flour, Full Fat", | |
"measures":[ | |
] | |
}, | |
{ | |
"id":7244, | |
"description":"Acorn Stew (Apache)", | |
"measures":[ | |
] | |
}, | |
{ | |
"id":3651, | |
"description":"Acorns, Dried", | |
"measures":[ | |
] | |
}, | |
{ | |
"id":3650, | |
"description":"Acorns, Raw", | |
"measures":[ | |
] | |
}, | |
{ | |
"id":1576, | |
"description":"Adobo Fresco", | |
"measures":[ | |
] | |
}, | |
{ | |
"id":7253, | |
"description":"Agave, Ckd (Southwest)", | |
"measures":[ | |
] | |
}, | |
{ | |
"id":7254, | |
"description":"Agave, Dried (Southwest)", | |
"measures":[ | |
] | |
}, | |
{ | |
"id":7252, | |
"description":"Agave, Raw (Southwest)", | |
"measures":[ | |
] | |
}, | |
{ | |
"id":7269, | |
"description":"Agutuk, Fish W/ Shortening (Alaskan Ice Cream) (Alaska Native", | |
"measures":[ | |
] | |
}, | |
{ | |
"id":7120, | |
"description":"Agutuk, Fish/Berry W/ Seal Oil (Ice Cream) (Alaska Native)", | |
"measures":[ | |
] | |
}, | |
{ | |
"id":7121, | |
"description":"Agutuk, Meat-Caribou (Alaskan Ice Cream) (Alaska Native)", | |
"measures":[ | |
] | |
}, | |
{ | |
"id":4087, | |
"description":"Alcoholic Bev, Beer, Lt", | |
"measures":[ | |
] | |
}, | |
{ | |
"id":4088, | |
"description":"Alcoholic Bev, Beer, Lt, Bud Lt", | |
"measures":[ | |
] | |
}, | |
{ | |
"id":4086, | |
"description":"Alcoholic Bev, Beer, Lt, Budweiser Sel", | |
"measures":[ | |
] | |
}, | |
{ | |
"id":4091, | |
"description":"Alcoholic Bev, Beer, Lt, Michelob Ultra", | |
"measures":[ | |
] | |
}, | |
{ | |
"id":4084, | |
"description":"Alcoholic Bev, Beer, Reg, All", | |
"measures":[ | |
] | |
}, | |
{ | |
"id":4085, | |
"description":"Alcoholic Bev, Beer, Reg, Budweiser", | |
"measures":[ | |
] | |
}, | |
{ | |
"id":4100, | |
"description":"Alcoholic Bev, Creme De Menthe, 72 Proof", | |
"measures":[ | |
] | |
}, | |
{ | |
"id":4089, | |
"description":"Alcoholic Bev, Daiquiri, Cnd", | |
"measures":[ | |
] | |
}, | |
{ | |
"id":4090, | |
"description":"Alcoholic Bev, Daiquiri, Prepared-From-Recipe", | |
"measures":[ | |
] | |
} | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment