static async Task Main(string[] args) { //handwritten client var productHttpClient = new ProductHttpClient(); var result = await productHttpClient.GetProducts(); Console.WriteLine(JsonSerializer.Serialize(result)); //library var productGraphQlClient = new ProductGraphQlClient(); var prod1 = await productGraphQlClient.GetProduct(1); Console.WriteLine(JsonSerializer.Serialize(prod1)); //mutation var newReview = await productGraphQlClient.AddReview(new ProductReviewModelInput { ProductId = 1, Title = "review" }); Console.WriteLine(JsonSerializer.Serialize(newReview)); productGraphQlClient.SubscribeToUpdates(); Console.ReadKey(); }
public HomeController( ProductHttpClient httpClient, ProductHttpClient2 httpClient2, // with httpclient factory ProductGraphClient productGraphClient) { _httpClient = httpClient; _httpClient2 = httpClient2; _productGraphClient = productGraphClient; }
public override void ViewDidLoad() { base.ViewDidLoad(); ProductHttpClient.getProducts((productList) => { // success var someProduct = productList[0]; Console.WriteLine($"Price before: {someProduct.CostPrice}"); }, (exception) => { // failure }); /* * // GET * var getRequest = new RestRequest("/products"); * client.ExecuteAsync<Payload<Product>>(getRequest, response => { * * var products = response.Data.collection; * var someProduct = products[0]; * Console.WriteLine($"Price before: {someProduct.CostPrice}"); * * // Update * someProduct.CostPrice += 1; * var putRequest = new RestRequest($"/products/{someProduct.ProductNumber}"); * putRequest.AddJsonBody(someProduct); * client.PutAsync<Product>(putRequest, (resp, req) => { * var updatedProduct = resp.Data; * Console.WriteLine($"Price after: {updatedProduct.CostPrice}"); * * // Finally create a copy * // POST * var postRequest = new RestRequest("/products"); * client.PostAsync<Product>(postRequest, (postResp, postReq) => { * var newProduct = resp.Data; * Console.WriteLine($"New product, same price: {newProduct.CostPrice}"); * }); * }); * });*/ }
public HomeController(ProductHttpClient productHttpClient, ProductGraphQLClient productGraphQLClient) { _productHttpClient = productHttpClient; _productGraphQLCLient = productGraphQLClient; }
public HomeController(ProductHttpClient httpClient, ProductGraphClient productGraphClient) { _httpClient = httpClient; _productGraphClient = productGraphClient; }
public ProductController(ProductHttpClient client) { _client = client; }
public override void ViewDidLoad() { base.ViewDidLoad(); var products = new List <Product>(); //GET ProductHttpClient.GetProducts((productList) => { //success products = productList; Console.WriteLine($"Price before on product no. 1: {products[0].costPrice}"); var selectedProduct = products[0]; selectedProduct.costPrice += 1; //UPDATE ProductHttpClient.UpdateProduct(selectedProduct, (product) => { //success Console.WriteLine($"Price after: {product.costPrice}"); var productToInsert = product; productToInsert.name = "CopyProduct"; productToInsert.productNumber = "sfasgfa213123"; //POST ProductHttpClient.InsertProduct(productToInsert, (newProduct) => { // success Console.WriteLine($"New product, same price: {newProduct.costPrice}"); }, (exception) => { throw exception; //TODO }); }, (exception) => { throw exception; //TODO }); }, (exception) => { throw exception; //TODO ? }); /* * * * * * */ /* * // GET * var getRequest = new RestRequest("/products"); * client.ExecuteAsync<Payload<Product>>(getRequest, response => { * * var products = response.Data.collection; * var someProduct = products[0]; * Console.WriteLine($"Price before: {someProduct.CostPrice}"); * * // Update * someProduct.CostPrice += 1; * var putRequest = new RestRequest($"/products/{someProduct.ProductNumber}"); * putRequest.AddJsonBody(someProduct); * client.PutAsync<Product>(putRequest, (resp, req) => { * var updatedProduct = resp.Data; * Console.WriteLine($"Price after: {updatedProduct.CostPrice}"); * * // Finally create a copy * // POST * var postRequest = new RestRequest("/products"); * client.PostAsync<Product>(postRequest, (postResp, postReq) => { * var newProduct = resp.Data; * Console.WriteLine($"New product, same price: {newProduct.CostPrice}"); * }); * }); * });*/ }