Last active
September 21, 2016 10:39
-
-
Save mebjas/e0d65b0930e2fe81cc02e8b95985ad50 to your computer and use it in GitHub Desktop.
handelling post with web api
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Net; | |
using System.Net.Http; | |
using System.Web.Http; | |
using System.Net.Http.Headers; | |
namespace testwebapp.Controllers | |
{ | |
public class OMSInput { | |
public string severity = String.Empty; | |
public string description = String.Empty; | |
}; | |
public class ValuesController : ApiController | |
{ | |
// GET api/values | |
public IEnumerable<string> Get() | |
{ | |
return new string[] { "value1", "value2" }; | |
} | |
// GET api/values/5 | |
public string Get(int id) | |
{ | |
return "value"; | |
} | |
// POST api/values | |
[HttpPost] | |
public HttpResponseMessage Post([FromBody]OMSInput value) | |
{ | |
var resp = new HttpResponseMessage() | |
{ | |
Content = new StringContent("{\"ack\":\"true\"}") | |
}; | |
resp.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); | |
return resp; | |
} | |
// PUT api/values/5 | |
public void Put(int id, [FromBody]string value) | |
{ | |
} | |
// DELETE api/values/5 | |
public void Delete(int id) | |
{ | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment