Implementing an API Gateway in ASP.NET Core with Ocelot

Learn what an API Gateway is and how to build yours in ASP.NET Core by using Ocelot.
Read more…

:writing_hand:t2: Brought to you by @joydipkanjilal

What’s up Devs! How did you like this post? Please share any comments or feedback with us on this thread :speaking_head:

Can you explain the below line -
services.AddOcelot(Configuration);

What does Configuration mean this context. Is it an object or do we need to add any namespace for it

Tagging article author here @joydipkanjilal for visibility!

The AddOcelot overloaded method adds ocelot services - in this example, we’re passing an instance of type IConfiguration (the instance name is Configuration) to the AddOcelot method as an argument. Hope this helps!

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.

I have have been trying to implement IP Rate Limit on Ocelot with no success. The configuration below is not taking IP Address into account
“RateLimitOptions”: {
“ClientWhitelist”: [
],
“EnableRateLimiting”: true,
“Period”: “10s”,
“PeriodTimespan”: 1,
“Limit”: 1,
“HttpStatusCode”: 429
}

I tried this with a colleague, We both got rate limited even when we were not supposed to. We decided to log our IP address on the service behind the API Gateway (Ocelot), at least the service could pick up the different IP Addresses, maybe because we added this

“UpstreamHeaderTransform”: {
“X-Forwarded-For”: “{RemoteIpAddress}”
}

app.UseForwardedHeaders(new ForwardedHeadersOptions { ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto });

So now we are thinking of applying rate limit on the service behind. Which is really not idea as it means we are not getting the full benefits of using Ocelot for our API GW.

Can you please advise where we might be getting things wrong

Hi, I take this back. I did some more digging and found where my issue was. I put the following under GlobalConfiguration, and it worked like a charm.

“RateLimitOptions”: {
“DisableRateLimitHeaders”: false,
“QuotaExceededMessage”: “Customize Tips!”,
“HttpStatusCode”: 429,
“ClientIdHeader”: “X-Forwarded-For”
}

Thanks a lot for your post

Hi @StavoG,
Glad to hear that you solved your problem, and thank you so much for sharing the solution! :pray: