public HttpResponseMessage Post(Hello message) { if (message == null) throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "You must supply a hello message.")); string id = Guid.NewGuid().ToString(); _helloMessages.Add(id, message.Message); var response = Request.CreateResponse(HttpStatusCode.Created, message.Message); var link = Url.Link("DefaultApi", new { controller = "Hello", id = id }); response.Headers.Location = new Uri(link); return response; }
public HttpResponseMessage Put(string id, Hello message) { if (message == null) throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "You must supply a hello message.")); _helloMessages[id] = message.Message; var response = _helloMessages.ContainsKey(id) ? Request.CreateResponse(HttpStatusCode.Created, message.Message) : Request.CreateResponse(HttpStatusCode.NoContent); var link = Url.Link("DefaultApi", new { controller = "Hello", id = id }); response.Headers.Location = new Uri(link); return response; }