Can Ocelot have own Controllers & Actions? #1949
-
Need implementation exampleTrying to create API gateway which also uses it's own Web API Controllers to handle mashups and any other custom code, using Ocelot for pipeline items like rate limiting, Authorization, and caching.I am trying to put together an API gateway that also serves the purpose of mashing up calls to multiple APIs. I would also like to have autogenerated Swagger, so I'd like to combine the capability of Ocelot for authorization and rate limiting but would also like to be able to create the edge custom API's in .NET code to handle translations and combinations of API calls. Is this possible with Ocelot, and are there any examples? Does Ocelot only work with downstream API's as separate applications? I'm trying to avoid an extra hop that would only exist for mashups and composite API calls. Stack Overflow related item: https://stackoverflow.com/questions/56956831/can-ocelot-have-its-own-controller-actions |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 3 replies
-
Is this sorted? Can we have custom logic in ocelet's own controller? Let's say I want to call 2nd downstream API based on the response of the 1st.. |
Beta Was this translation helpful? Give feedback.
-
Something new? |
Beta Was this translation helpful? Give feedback.
-
Hi @kvansaders, @masanand and @szymonpiekny,
services.AddSwaggerForOcelot(configuration, (o) =>
{
o.GenerateDocsForGatewayItSelf = true;
});
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
}); With such configuration you will be able to run standard downstream / upstream setup with ocelot and swagger (need additional configuration in ocelot.json) and your custom api for any needs. |
Beta Was this translation helpful? Give feedback.
-
I'm sharing the entire Program.cs code if anyone is interested. Unfortunately ASP0014 error cannot be suprased without var builder = WebApplication.CreateBuilder(args);
builder.Services.AddOcelot(builder.Configuration);
var app = builder.Build();
app.UseRouting();
app.MapControllers();
#pragma warning disable ASP0014
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
#pragma warning restore ASP0014
app.UseOcelot();
app.MapGet("/identity/authenticate", () => "token");
app.Run(); |
Beta Was this translation helpful? Give feedback.
Hi @kvansaders, @masanand and @szymonpiekny,
Recently I was working on similar PoC for one of the projects I'm working on and my main goal was to have endpoints like @kvansaders mentioned to be able to have possibility mehsup / service enhance / add specific aggregation in case of one call to API G. with multiple walls internally or hide old / ugly API and what was more important for me to be able to call to API G. to publish a message to a broker. My first approach was to have middleware which worked but I wasn't able to create out of box swagger. Then I get to this topic of Ocelot own APIs.
After standard Ocelot configuration on .NET 6 project with some downstream projects what I did ad…