Skip to content

Instantly share code, notes, and snippets.

View SibeeshVenu's full-sized avatar
🙂
Learning and Sharing

Sibeesh Venu SibeeshVenu

🙂
Learning and Sharing
View GitHub Profile
async Task MyAPIDelete(HttpClient cons)
{
using (cons)
{
HttpResponseMessage res = await cons.GetAsync("api/tblTags/2");
res.EnsureSuccessStatusCode();
if (res.IsSuccessStatusCode)
{
res = await cons.DeleteAsync("api/tblTags/2");
Console.WriteLine("\n");
tag.tagName = "New Tag";
res = await cons.PutAsJsonAsync("api/tblTags/2", tag);
static async Task MyAPIPut(HttpClient cons)
{
using (cons)
{
HttpResponseMessage res = await cons.GetAsync("api/tblTags/2");
res.EnsureSuccessStatusCode();
if (res.IsSuccessStatusCode)
{
tblTag tag = await res.Content.ReadAsAsync<tblTag>();
tag.tagName = "New Tag";
static async Task MyAPIGet(HttpClient cons)
{
using (cons)
{
HttpResponseMessage res = await cons.GetAsync("api/tblTags/2");
res.EnsureSuccessStatusCode();
if (res.IsSuccessStatusCode)
{
tblTag tag = await res.Content.ReadAsAsync<tblTag>();
Console.WriteLine("\n");
HttpClient cons = new HttpClient();
cons.BaseAddress = new Uri("http://localhost:7967/");
cons.DefaultRequestHeaders.Accept.Clear();
cons.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
public class tblTag
{
public int tagId { get; set; }
public string tagName { get; set; }
public string tagDescription { get; set; }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace WebAPIWithHttpClientConsumer
{
class Program
{
static void Main(string[] args)
{
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using System.Web.Http;
USE [TrialsDB]
GO
INSERT INTO [dbo].[tblTags]
([tagName]
,[tagDescription])
VALUES
(<tagName, nvarchar(50),>
,<tagDescription, nvarchar(max),>)
GO
USE [TrialsDB]
GO
/****** Object: Table [dbo].[tblTags] Script Date: 23-Mar-16 5:01:22 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO