// POST api/Match, request body contains client information serialized as XML or JSON public HttpResponseMessage PostAddPerson(MatchInfo matchSearch) { if (ModelState.IsValid) // model class validation ok? { // check for duplicate // LINQ query - count number of people with ID int count = context.Match.Where(l => l.ID.ToUpper() == matchSearch.ID.ToUpper()).Count(); if (count == 0) { MatchInfo.Add(matchSearch); // create http response with Created status code and listing serialised as content and Location header set to URI for new resource var response = Request.CreateResponse <MatchInfo>(HttpStatusCode.Created, matchSearch); string uri = Url.Link("DefaultApi", new { id = matchSearch.ID }); // name of default route in WebApiConfig.cs response.Headers.Location = new Uri(uri); // Location URI for newly created resource return(response); } else { throw new HttpResponseException(HttpStatusCode.NotFound); // 404 } } else { throw new HttpResponseException(HttpStatusCode.BadRequest); // 400, malformed request } }