-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathsample9.cs
More file actions
36 lines (29 loc) · 1.04 KB
/
sample9.cs
File metadata and controls
36 lines (29 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
static void ListAllProducts()
{
HttpResponseMessage resp = client.GetAsync("api/products").Result;
resp.EnsureSuccessStatusCode();
var products = resp.Content.ReadAsAsync<IEnumerable<SelfHost.Product>>().Result;
foreach (var p in products)
{
Console.WriteLine("{0} {1} {2} ({3})", p.Id, p.Name, p.Price, p.Category);
}
}
static void ListProduct(int id)
{
var resp = client.GetAsync(string.Format("api/products/{0}", id)).Result;
resp.EnsureSuccessStatusCode();
var product = resp.Content.ReadAsAsync<SelfHost.Product>().Result;
Console.WriteLine("ID {0}: {1}", id, product.Name);
}
static void ListProducts(string category)
{
Console.WriteLine("Products in '{0}':", category);
string query = string.Format("api/products?category={0}", category);
var resp = client.GetAsync(query).Result;
resp.EnsureSuccessStatusCode();
var products = resp.Content.ReadAsAsync<IEnumerable<SelfHost.Product>>().Result;
foreach (var product in products)
{
Console.WriteLine(product.Name);
}
}