ASP.NET Core Api-Gateway middleware

前端 未结 2 827
执笔经年
执笔经年 2021-02-07 12:55

I am new to API gateways and have a question of understanding. I try too put a series of (micro)services behind an endpoint.

For this purpose, I have set up an ASP.NET C

2条回答
  •  逝去的感伤
    2021-02-07 13:36

    Your architecture design is wrong!

    First, let's find out what this the API Gateway.

    An API Gateway is programming that sits in front of an application programming interface (API) and acts as a single point of entry for a defined group of microservices.

    A major benefit of using API gateways is that they allow developers to encapsulate the internal structure of an application in multiple ways, depending upon use case. This is because, in addition to accommodating direct requests, gateways can be used to invoke multiple back-end services and aggregate the results.

    Ok, the name "API Gateway" shows us that it is mostly intended for API services! SPA or MVC applications are not back-end services. You should not put your front-end applications behind the api gateway.

    In general, your architecture should look like this:

    An API gateway is the single entry point for all clients. SPA is client of your services and should call it through API Gateway. If your application has multiple client apps, that can be a primary pivot when identifying the multiple API Gateways types, so that you can have a different facade for the needs of each client app. This case is a pattern named “Backend for Frontend” (BFF) where each API Gateway can provide a different API tailored for each client app type.

    What if you don't want to build a proper architecture?

    1. You can configure redirect. It is something like to specify a default service of API gateway. Then all clients that go to http://mygateway:4242/ will redirected to http://mygateway:4242/s3/
    2. Ocelot allows Middleware Injection. So, you can inject your custom middleware where you will check which request and where to redirect it.
    3. Use CDN to store all css and other content.
    4. Inline css into html files.

提交回复
热议问题