0

I want to return from a request if there's already a request in process from that client.

// Controller

public async Task<IHttpActionResult> GetBarcode(string ticketId)
{
    var customerGuid = Guid.Parse(User.Identity.GetUserId());
    var ticketGuid = Guid.Parse(ticketId);

    return Json(await _service.GetBarcode(customerGuid, ticketGuid));
}

// Service

public async Task<TicketBarcode> GetBarcode(Guid customerId, Guid ticketId)
{

    // if already processing a request with this customerId and ticketId, then return

    // if not, then proceed

It calls another API which can't handle the pressure.

I'm asking for advice how to achieve this. If you need more info, please comment.

1 Answers1

0

If I understood your question correctly; you want something that prevent users to call your apis frequently. Well, there are multiple ways to achieve it.

You can use Radis; it provides different patterns for Rate limiter, with use of that you'd able to configure rate limit e.g. maximum of ten requests per second per IP address.

Another straight forward way is to use nuget package of WebApiThrottle.

Divyang Desai
  • 7,483
  • 13
  • 50
  • 76