Created
October 7, 2020 07:36
-
-
Save rahulsahay19/97789226a699275478e13dcfc87584cb to your computer and use it in GitHub Desktop.
MoviesController.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.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