Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
[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
You can’t perform that action at this time.