Skip to content

Instantly share code, notes, and snippets.

@rfaisal
Created January 14, 2014 16:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rfaisal/8421007 to your computer and use it in GitHub Desktop.
Save rfaisal/8421007 to your computer and use it in GitHub Desktop.
[EnableCors(origins: "*", headers: "*", methods: "*")]
// [Authorize]
public class ValuesController : ApiController
{
private static List<string> values = new List<string>();
// GET api/values
public IEnumerable<string> Get()
{
return values;
}
// GET api/values/?index=3
public string Get(int index)
{
return values.ElementAtOrDefault(index);
}
// POST api/values
public void Post([FromBody]string value)
{
values.Add(value);
}
// PUT api/values/5
public void Put(int index, [FromBody]string value)
{
if (values.Count > index)
values[index] = value;
else
Post(value);
}
// DELETE api/values/5
public void Delete(int index)
{
if (values.Count > index)
values.RemoveAt(index);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment