Skip to content

Instantly share code, notes, and snippets.

@sakapon
Last active March 22, 2018 08:14
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 sakapon/1e5d10ca0b5b7a5435ba2a8c52072348 to your computer and use it in GitHub Desktop.
Save sakapon/1e5d10ca0b5b7a5435ba2a8c52072348 to your computer and use it in GitHub Desktop.
AspNetWebApiSample/SampleWebApi/Controllers/RandomController.cs
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