Last active
March 22, 2018 08:14
-
-
Save sakapon/1e5d10ca0b5b7a5435ba2a8c52072348 to your computer and use it in GitHub Desktop.
AspNetWebApiSample/SampleWebApi/Controllers/RandomController.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 | |
{ | |
[RoutePrefix("api/Random")] | |
[Route("{action}")] | |
public class RandomController : ApiController | |
{ | |
static readonly Random random = new Random(); | |
[HttpGet] | |
[Route("Echo/{i:int?}")] | |
public int Echo(int i = 123) => i; | |
[HttpGet] | |
[Route("NewDoubles/{count:int:range(0,64)}")] | |
public double[] NewDoubles(int count) => | |
Enumerable.Range(0, count) | |
.Select(i => random.NextDouble()) | |
.ToArray(); | |
[HttpGet] | |
[Route(@"NewDateTime/{date:datetime:regex(\d{4}-\d{2}-\d{2})}")] | |
[Route(@"NewDateTime/{*date:datetime:regex(\d{4}/\d{2}/\d{2})}")] | |
public DateTime NewDateTime(DateTime date) => date + TimeSpan.FromHours(24 * random.NextDouble()); | |
[HttpGet] | |
public Guid NewUuid() => Guid.NewGuid(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment