Skip to content

Instantly share code, notes, and snippets.

@rahulsahay19
Created October 7, 2020 07:36
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 rahulsahay19/97789226a699275478e13dcfc87584cb to your computer and use it in GitHub Desktop.
Save rahulsahay19/97789226a699275478e13dcfc87584cb to your computer and use it in GitHub Desktop.
MoviesController.cs
using System;
using System.Threading;
using Microsoft.AspNetCore.Mvc;
namespace MoviesAPI.Controllers
{
[ApiVersion("1")]
[Route("api/v{version:apiVersion}/[controller]")]
[ApiController]
public class MoviesController : ControllerBase
{
private static int _count = 0;
private static readonly string[] Movies = new[]
{
"Die Another Day", "Top Gun", "Grease", "Dil Bechara", "Jurassic Park"
};
[HttpGet]
public ActionResult Get()
{
_count++;
Console.WriteLine($"get...{_count}");
if (_count <= 5)
{
Thread.Sleep(5000);
}
var rng = new Random();
return Ok(Movies[rng.Next(Movies.Length)]);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment