Created
March 22, 2018 12:34
-
-
Save sakapon/7641318950b9e61a4537ecc9feff397b to your computer and use it in GitHub Desktop.
AspNetWebApiSample/SampleWebApi/Controllers/ValuesController.cs
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; | |
namespace SampleWebApi.Controllers | |
{ | |
public class ValuesController : ApiController | |
{ | |
static readonly List<string> values = new List<string> { "value0", "value1" }; | |
public string Get(int id) | |
{ | |
if (id < 0 || values.Count <= id) | |
{ | |
var message = $"No value with ID = {id}"; | |
throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.NotFound, message)); | |
// No content: | |
//throw new HttpResponseException(HttpStatusCode.NotFound); | |
} | |
return values[id]; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment