How to build an API Gateway in ASP.NET Core using Ocelot (Build API Gateway in a few minutes)

แชร์
ฝัง
  • เผยแพร่เมื่อ 22 ส.ค. 2020
  • API Gateway is an API management tool that usually sits between the external caller (Web or Mobile) and the internal services. The API Gateway can provide multiple features like:
    1. Routing
    2. Request Aggregation
    3. Authentication
    4. Authorization
    5. Rate Limiting
    6. Caching
    7. Load Balancing
    ETC.
    Ocelot is an ASP.Net Core (Supports .Net Core 3.1) API Gateway. It's a NuGet package, which can be added to any ASP.Net Core application to make it an API Gateway.
    Ocelot API Gateway supports all the features that any standard API Gateway does.
    I will cover the following features of Ocelot API Gateway in this video:
    1. Routing (Basic routing to internal service)
    2. Authentication (JWT Token-based authentication)
    3. Response Caching (Using Ocelot.Cache.CacheManager NuGet package)
    4. Rate limiting
    More information about Ocelot API Gateway is available in their website here: ocelot.readthedocs.io/en/late...
    The source code for this video is available in my GitHub repo here: github.com/choudhurynirjhar/oc...
  • วิทยาศาสตร์และเทคโนโลยี

ความคิดเห็น • 140

  • @rajesh35hsp
    @rajesh35hsp ปีที่แล้ว

    to the point and precise. thank you for this.

  • @nagesh46s
    @nagesh46s 2 ปีที่แล้ว +1

    Awesome explanation. Entire source code is also shared. Up voted. Keep up your good work sir.

  • @savithapn1790
    @savithapn1790 10 หลายเดือนก่อน

    Great presentation , i like the way you explain any hard topic in a simple way so that anyone can understand, keep up the good work !

  • @nguyenminhat6594
    @nguyenminhat6594 3 ปีที่แล้ว +2

    I'm beginning to learn Microservices. Thank you so much for this video. It's very helpful for me :D

  • @umeshkushwaha01
    @umeshkushwaha01 ปีที่แล้ว

    Very well explained. I appreciate your effort Nirjhar. It was honored to work with you.

    • @DotNetCoreCentral
      @DotNetCoreCentral  ปีที่แล้ว

      @Umesh Kushwaha, thanks for watching! It was a pleasure to work with you as well!

  • @hannesbergsten1134
    @hannesbergsten1134 2 ปีที่แล้ว

    Awsome video, I will try this tomorrow. Thanks alot!

  • @sreedharcb3120
    @sreedharcb3120 2 ปีที่แล้ว +1

    great video!, explained in simple steps. Thank you :)

  • @ramsys9906
    @ramsys9906 3 ปีที่แล้ว +1

    Superb Presentation. What I like the most was the "style" in which you presented.... crystal crisp clear voice, no high or low pitch in your voice, going at constant steady speed, up to the point explaining each step properly, no shuffling from one screen to another (its very irritating) which makes to loose link. Looks like you have taken pains to plan your presentation well in advance keep up with the good work.

  • @pauldechampignon2287
    @pauldechampignon2287 2 ปีที่แล้ว

    Amazing material. Thanks!

  • @sau002
    @sau002 2 ปีที่แล้ว

    Nice demo. Thank you

  • @Aweklin
    @Aweklin ปีที่แล้ว

    Thanks a bunch for this video. It's now clearer to me how to use it.

  • @RAM-ff8dy
    @RAM-ff8dy 3 ปีที่แล้ว

    I always wait for your videos.,,great stuff..Really appreciate all your efforts..waiting for videos on Azure service bus, Azure Functuons,Azure MessageQueueing,Azure App Insights...etc

    • @DotNetCoreCentral
      @DotNetCoreCentral  3 ปีที่แล้ว

      @RAM, I will start with AWS as I work on AWS every day, will do Azure as well alongside.

    • @randomphilic27
      @randomphilic27 2 ปีที่แล้ว

      @@DotNetCoreCentral pls if made can u give the exact link?

  • @RameshKumar-gr1dt
    @RameshKumar-gr1dt 2 ปีที่แล้ว

    Thank You Sir.. This is really great video.

  • @ravijsoni2477
    @ravijsoni2477 2 ปีที่แล้ว

    Helpful. Thanks

  • @imoto8709
    @imoto8709 2 ปีที่แล้ว

    sehr gut!

  • @navaneethakrishnan1532
    @navaneethakrishnan1532 3 ปีที่แล้ว

    Well Done....Nice Article....

  • @JustCode512
    @JustCode512 6 หลายเดือนก่อน

    my rate 10/10 thanks man!

  • @ashokb3648
    @ashokb3648 3 ปีที่แล้ว

    👍Awesome👏

  • @user-kh8zm3on2b
    @user-kh8zm3on2b 8 หลายเดือนก่อน

    that is amazing, thank you!

  • @mahendranchinnaiah7593
    @mahendranchinnaiah7593 3 ปีที่แล้ว +2

    Great Job.. I like to watch all of your videos. Please try some concepts in cloud environment(AWS,Azure)

  • @11shriji11
    @11shriji11 2 ปีที่แล้ว +2

    Question: Can you please explain or extend this example with Kubernetes please? I found this helpful and I have implemented the same with Docker (docker desktop) but couldn't find much materials to extend in kubernetes.

  • @kalyankumarsubramaniyan6405
    @kalyankumarsubramaniyan6405 3 ปีที่แล้ว

    thank you very much for your video. Please do a video for certificate based authentication

    • @DotNetCoreCentral
      @DotNetCoreCentral  3 ปีที่แล้ว

      @Kalyan Kumar, I will try. Thanks for watching it.

  • @channing9705
    @channing9705 3 ปีที่แล้ว +1

    Thanks for the video ! Actually the keys are different in two videos ("This is my test key" vs. "Thisismytestprivatekey"), maybe that's why some people fail the test :D

    • @DotNetCoreCentral
      @DotNetCoreCentral  3 ปีที่แล้ว

      @Channing, thanks for watching! I think I changed the key while some testing, thanks for the catch.

  • @shuhaib864
    @shuhaib864 3 ปีที่แล้ว

    Thanks 🙏

  • @talhatariq5530
    @talhatariq5530 7 หลายเดือนก่อน

    Greatly Explained! Kindly I request to Create a PlayList on API Gateways. Regards

  • @pt_trainer9244
    @pt_trainer9244 หลายเดือนก่อน

    Very concise tutorial, thank you.
    I added a Middleware in my individual services to check for a specific header that I only set at the gateway level so that clients cant call my microservice endpoints directly, but only through the gateway.
    Is there a better way to handle this for local dev. (Not using NSG in Cloud Service etc)

  • @alexreg78
    @alexreg78 3 ปีที่แล้ว

    What is great in ocelot
    Prog never STOP)

    • @DotNetCoreCentral
      @DotNetCoreCentral  3 ปีที่แล้ว

      @МАЙК САХАРОВ, thanks for watching! I am not sure I understood the question.

  • @computerprogrammingadvance2612
    @computerprogrammingadvance2612 2 ปีที่แล้ว

    Thanks

  • @govardhanm3703
    @govardhanm3703 ปีที่แล้ว

    Good explanation Nirjhar, about the concepts.
    If possible share the related links in creating Authorization token (JWT) project in Description. Thanks.

  • @tomfanara3743
    @tomfanara3743 2 ปีที่แล้ว

    Hello Sir, Great videos and very clear! Do you have a simple Ocelot api gateway in docker compose? I'm having difficulty with the routings for a single GET service!

    • @DotNetCoreCentral
      @DotNetCoreCentral  2 ปีที่แล้ว

      @
      Tom Fanara, thanks for watching!
      I have used the standard docker image for .NET Core 3.1 and .NET 5 and that worked for me.

  • @MobileEpics
    @MobileEpics 2 ปีที่แล้ว

    how did you get the JWT token that is used in Postman???

  • @niknik5293
    @niknik5293 2 ปีที่แล้ว

    will the cache be logged out to the console? can't seem to tell if the responses are returned from the cache or not in a POC app

  • @FurqanaFathuzzaman
    @FurqanaFathuzzaman 3 ปีที่แล้ว +3

    This is an awesome video!
    I have a question, though. Where or how the gateway find the authentication server? I didn't see you state the address (localhost:5030) anywhere

    • @DotNetCoreCentral
      @DotNetCoreCentral  3 ปีที่แล้ว

      @Furqana Fathuzzaman, I used one of the auth servers I created in one of my previous videos for auth demo here: th-cam.com/video/vWkPdurauaA/w-d-xo.html

    • @FurqanaFathuzzaman
      @FurqanaFathuzzaman 3 ปีที่แล้ว +1

      @@DotNetCoreCentral
      I mean, how does the gateway (or other service) find the auth service? IIRC some example in the past state the auth service url in jwt authority or issuer, but I didn't see it being configured here. Does it have some technique to automatically find it?
      In the auth demo video, the api and auth service is in the same project/url, so I don't think it was needed. But in this one, the service is on different address (different port).
      Sorry if I missed something, I'm still grasping around the concept of separated identity service for microservice.

    • @DotNetCoreCentral
      @DotNetCoreCentral  3 ปีที่แล้ว

      @@FurqanaFathuzzaman In this example I am using JWT Authentication token, hence I am not calling back to the Identity server to find out what the user's identity. As for JWT Token, the user information is inside of the token in encoded format. Let me know if it makes sense. And as you can see in 05:20, I am passing the same secret key as in the authentication server, hence I am able to validate the token from here.

    • @aumidbek
      @aumidbek 3 ปีที่แล้ว

      @@FurqanaFathuzzaman I don't understand this moment too. How to solve this?

    • @brienfoaboutanything9037
      @brienfoaboutanything9037 2 ปีที่แล้ว

      Thats amazing information about Ocelot: th-cam.com/video/oAij1Ntt5Ps/w-d-xo.html

  • @manuelguerrero9917
    @manuelguerrero9917 3 ปีที่แล้ว

    Super helpful video as always, I have a question about cache.
    Cache is going to return the same result from memory even though the data in the Microservices changed ?

    • @DotNetCoreCentral
      @DotNetCoreCentral  3 ปีที่แล้ว +1

      @Manuel Guerrero, thanks for watching!
      To answer your question, yes, the cache will return data from the cache irrespective of changes in the microservice as long as the cache is not expired.
      And that is why it is important to cache items which make sense even if the data is a little stale based on business requirement.
      Most of the time, report type of data would make sense to cache, not something like product inventory.

    • @naval207
      @naval207 3 ปีที่แล้ว

      @@DotNetCoreCentral If data is changed in microservices you have to fie the even and clear the cache in memory. memory service should be listen the event and clear the data.

    • @naval207
      @naval207 3 ปีที่แล้ว

      You have to push the event when any changes happened in microservice , subscribe that even at memory cache

    • @DotNetCoreCentral
      @DotNetCoreCentral  3 ปีที่แล้ว

      @@naval207 I am not sure I understand what you are trying to conclude here. As I mentioned earlier, the only thing we should be caching is, and I quote "And that is why it is important to cache items which make sense even if the data is a little stale based on business requirement.
      Most of the time, report type of data would make sense to cache, not something like product inventory."
      Again Ocelot is not a caching solution, the caching feature it provides should only be used for some convenience not for full-fledged caching, for that we should use distributed cache like Redis.

  • @amitbajaj1995
    @amitbajaj1995 ปีที่แล้ว

    Hi, Which Opensource API gateway would you recommend for heavy load , several applications and microservices. ?

    • @DotNetCoreCentral
      @DotNetCoreCentral  ปีที่แล้ว

      I have used Ocelot in prod with heavy load, have not seen any issues.

  • @arkadiyshuvaev
    @arkadiyshuvaev 2 ปีที่แล้ว

    Hello everybody. It seems to me that Ocelot has stopped developing since December 2020. Has anybody started looking for a substitute for Ocelot?
    What service can do request aggregation?
    Thank you in advance.

  • @ahsannisar915
    @ahsannisar915 2 ปีที่แล้ว

    Sir please tell me about, how to Take input multiple "Roles" for a single user as a input(login) in ocelot gateway.

  • @semen083
    @semen083 2 ปีที่แล้ว

    It is no need in Ocelot when run apps in k8s?

  • @amanjotsingh6232
    @amanjotsingh6232 2 ปีที่แล้ว

    hello sir, can we access two different microservices which are present in different solutions using ocelot,if yes plz tell me how, if not then plz tell me the alternative to do this

  • @indranilbaidya7730
    @indranilbaidya7730 3 ปีที่แล้ว

    What will b the url, after hoisting api gateway on iis ? N I'm not using jwt, I'm using owin. How can I configure owin on apigateway ?

    • @DotNetCoreCentral
      @DotNetCoreCentral  3 ปีที่แล้ว

      @Indranil Baidya, the URL in IIS will be based on whatever virtual directory you are creating it inside. I do not think Ocelot supports anything below .Net Core 3.1 based on what I have seen its project configuration here: github.com/ThreeMammals/Ocelot/blob/master/src/Ocelot/Ocelot.csproj

  • @duongtuandat84
    @duongtuandat84 2 ปีที่แล้ว

    As I understand, now all API call will go through Ocelot, so does it make slow or bottle-neck the transactions?

    • @DotNetCoreCentral
      @DotNetCoreCentral  2 ปีที่แล้ว +1

      It will not if it is scaled properly, though it will introduce single-digit milliseconds latency, but that will be the case of any gateway.

  • @chiragtank6359
    @chiragtank6359 2 ปีที่แล้ว

    is there required to impement AddAuthentication in every micro service startup class file for auhorization ?

    • @DotNetCoreCentral
      @DotNetCoreCentral  2 ปีที่แล้ว

      If you add it to the API Gateway, the individual microservices do not need to have authentication. But you will have to make sure the microservices are not accessible to the internet, meaning they are inside of a DMZ.

  • @dev4g276
    @dev4g276 2 ปีที่แล้ว

    plaease create on video on authentication and authoraization in microservices

  • @MrRavikishore2222
    @MrRavikishore2222 3 ปีที่แล้ว

    I want to implement Active Directory authentication in Gateway. Can you please one more Video or any sample code .

    • @DotNetCoreCentral
      @DotNetCoreCentral  3 ปีที่แล้ว

      @Ravi Kishore, I have not done anything with active directory authentication before. I will take a look and see if I can find something that might help you. Thanks

  • @arjaygregorio2019
    @arjaygregorio2019 3 ปีที่แล้ว

    Hi! New here! I would like to know if is it possible that ocelot api gateway to host it into windows 2016 server type?

    • @DotNetCoreCentral
      @DotNetCoreCentral  3 ปีที่แล้ว

      @Arjay Gregorio, thanks for watching. Yes it is possible to host anywhere, as long as you can run a .NET Core application.

  • @28687451
    @28687451 3 ปีที่แล้ว

    awesome videos hey can u tell me where u have specified auth servers in this video i tried the same watching you both video but getting error of badgateway 502

    • @DotNetCoreCentral
      @DotNetCoreCentral  3 ปีที่แล้ว

      @Sagar Shah, thanks for watching! I am not using any authentication mechanism in this app. I built an open API. Bad gateway might be because the API Gateway do not have access to the Lambda, I mentioned that during this video, and it really is done out of box by the API gateway.

    • @28687451
      @28687451 3 ปีที่แล้ว

      @@DotNetCoreCentral can u send me the link in which u have created open api?

  • @AbhinavSingh-ov7pj
    @AbhinavSingh-ov7pj 3 ปีที่แล้ว

    Here we are using token from existing app and passing to ocelot api.but in real world the ocelot api should expose something so that valid user can generate token right ?

    • @DotNetCoreCentral
      @DotNetCoreCentral  3 ปีที่แล้ว

      @Abhinav Singh, in real life as well the operation will be similar. The responsibility of the token provider is completely isolated from the API Gateway and it should be served by a third-party server. Which can be any of the cloud token providers or one of your own. API Gateway should not be in the business of providing tokens.
      That is the architectural principle I use.

    • @AbhinavSingh-ov7pj
      @AbhinavSingh-ov7pj 3 ปีที่แล้ว

      @@DotNetCoreCentral so first time when user will call ocelote api ,user will send login credential to api.Then ocelote api will route to another service( token provider) whose route is configured in ocelote api.now if credential are fine then token will be returned which will use by user for successive call.my understanding is correct ?

    • @DotNetCoreCentral
      @DotNetCoreCentral  3 ปีที่แล้ว

      @@AbhinavSingh-ov7pj yes!

  • @AmanGupta-fq5oq
    @AmanGupta-fq5oq 3 ปีที่แล้ว

    Hi, could you please tell me how to route an action posting a json body please

    • @DotNetCoreCentral
      @DotNetCoreCentral  3 ปีที่แล้ว

      @Aman Gupta, routing POST, GET, DELETE, PUT all are done the same way. There is no fundamental difference between HTTP method types when it comes to Ocelot API Gateway.

  • @indranilbaidya7730
    @indranilbaidya7730 3 ปีที่แล้ว

    I've used owin oauthauthorizationserveroption, oauthbearertoken. Plz guide me how can I use it in ocelot ?

    • @DotNetCoreCentral
      @DotNetCoreCentral  3 ปีที่แล้ว +1

      @Indranil Baidya, thanks for watching! I will try out owin with Ocelot and will let you know.

    • @indranilbaidya7730
      @indranilbaidya7730 3 ปีที่แล้ว

      @@DotNetCoreCentral That will be very help full.
      Waiting .......

    • @indranilbaidya7730
      @indranilbaidya7730 3 ปีที่แล้ว

      @@DotNetCoreCentral Any update on this ? Please let me know.

  • @gopalakrishnanm9349
    @gopalakrishnanm9349 3 ปีที่แล้ว +2

    pls put a video for consul with swagger in ocelot

    • @DotNetCoreCentral
      @DotNetCoreCentral  3 ปีที่แล้ว +2

      @Gopi HB, thanks for the suggestion, I will definitely do it in one of my future videos.

    • @gopalakrishnanm9349
      @gopalakrishnanm9349 3 ปีที่แล้ว

      @@DotNetCoreCentral thanks

    • @DotNetCoreCentral
      @DotNetCoreCentral  3 ปีที่แล้ว

      @@gopalakrishnanm9349 you are welcome!

  • @parthvohra5891
    @parthvohra5891 3 ปีที่แล้ว

    how did you got data from api/weather ? where is weather data file ?

    • @DotNetCoreCentral
      @DotNetCoreCentral  3 ปีที่แล้ว

      @Parth Vohra, I created a new WEB API project in ASP.NET Core 3.1 as a part of the video, when you create a new Web API project, by default it comes with a weather controller. The data comes from an in-memory data structure. Hope this answers your question. Thanks for watching!

  • @bloodeyhell7026
    @bloodeyhell7026 3 ปีที่แล้ว

    Can you make a video on service discovery

    • @DotNetCoreCentral
      @DotNetCoreCentral  3 ปีที่แล้ว

      @Da Prodigy, I surely can. I will put it on my calendar. Thanks for the suggestions.

  • @muhammadandikakurniawan7037
    @muhammadandikakurniawan7037 3 ปีที่แล้ว

    excuse me, i wanna ask about how to implement action filter for ocelot ?, for loging, thankyou

    • @DotNetCoreCentral
      @DotNetCoreCentral  3 ปีที่แล้ว

      @Muhammad andika Kurniawan, Ocelot out of box comes with comprehensive logging. What extra are you planning to log?

    • @muhammadandikakurniawan7037
      @muhammadandikakurniawan7037 3 ปีที่แล้ว

      @@DotNetCoreCentral i wanna log pre and after endpoint executed like use action filter, but i try setup my filter and it's no work for endpoint that registered in ocelot.json, only work for api that created in project :)

    • @DotNetCoreCentral
      @DotNetCoreCentral  3 ปีที่แล้ว

      @@muhammadandikakurniawan7037 A middleware should work in that case. If you are facing any issues with that, if you can share the code in Github, I can take a look.

  • @muhammeda1426
    @muhammeda1426 2 ปีที่แล้ว

    Do we have to request id like customer/1
    Or can we request like customer?customerid=1
    İf we can how?

    • @DotNetCoreCentral
      @DotNetCoreCentral  2 ปีที่แล้ว

      @M A, for query string parameters nothing specific needs to happen, as long as the base path is configured, whatever is in query string will be passed along.

    • @muhammeda1426
      @muhammeda1426 2 ปีที่แล้ว

      @@DotNetCoreCentral it worked thanks for answer

    • @DotNetCoreCentral
      @DotNetCoreCentral  2 ปีที่แล้ว

      @@muhammeda1426 welcome!

  • @manasupadhyay8101
    @manasupadhyay8101 3 ปีที่แล้ว

    Hey I have made the same API gateway and deployed it to Azure aks and it's not working

    • @DotNetCoreCentral
      @DotNetCoreCentral  3 ปีที่แล้ว

      @Manas Upadhyay, can you give a little bit more details, what error you see in the container logs etc.

    • @manasupadhyay8101
      @manasupadhyay8101 3 ปีที่แล้ว

      @@DotNetCoreCentral Ocelot.Responder.Middleware.ResponderMiddleware[0]
      requestId: 0HMACAC3LH4O0:00000002, previousRequestId: no previous request id, message: Error Code: RequestCanceled Message: The operation was canceled. errors found in ResponderMiddleware. Setting error response for request path:/gateway/claim, request method: GET

    • @DotNetCoreCentral
      @DotNetCoreCentral  3 ปีที่แล้ว

      @@manasupadhyay8101 the error says there is an issue with the configuration, can you share the ocelot configuration

    • @lismai9906
      @lismai9906 2 ปีที่แล้ว

      I had to figure this out myself because in your video it was not mentioned how to get authentication to work - Token Server's secret key string MUST match with ocelot.demo project in order to properly authenticate and successfully get the external api

  • @h.r134
    @h.r134 3 ปีที่แล้ว

    Can i use nodejs service when i use Ocelot?

    • @DotNetCoreCentral
      @DotNetCoreCentral  3 ปีที่แล้ว

      @Hr, the service Ocelot forwarding the request can be anything. But Ocelot itself needs to be hosted in a .NET Core server.

    • @h.r134
      @h.r134 3 ปีที่แล้ว

      @@DotNetCoreCentral thanks 🙏

    • @DotNetCoreCentral
      @DotNetCoreCentral  3 ปีที่แล้ว

      @@h.r134 you are welcome!

  • @user-eh9oi6wg7b
    @user-eh9oi6wg7b 3 ปีที่แล้ว

    Hello, where is the video of JWT server implementation

    • @DotNetCoreCentral
      @DotNetCoreCentral  3 ปีที่แล้ว

      @Иван Вангелов, here is the URL of JWT implementation: th-cam.com/video/vWkPdurauaA/w-d-xo.html

    • @user-eh9oi6wg7b
      @user-eh9oi6wg7b 3 ปีที่แล้ว

      @@DotNetCoreCentral Thank you :)

    • @DotNetCoreCentral
      @DotNetCoreCentral  3 ปีที่แล้ว

      @@user-eh9oi6wg7b welcome!

  • @johnkuriakose88
    @johnkuriakose88 3 ปีที่แล้ว

    Hi, Your video is very helpful.
    Can I implement Api gateway with Old aspnet.mvc web app. Do i need to separate the view from the MVC controller. How would that work. All the documents I see says that the view should be calling the Gateway that would mean that i will have write a lot of code.
    Do you know if there is another way.

    • @DotNetCoreCentral
      @DotNetCoreCentral  3 ปีที่แล้ว

      @John Kuriakose, thanks for watching!
      To be honest, API Gateway is not meant for something like the MVC app. It is meant for API, so if you are exposing RESTful API through MVC then you should use API Gateway with it.
      Let me know if it makes sense.

  • @hanm
    @hanm 3 ปีที่แล้ว

    Envoy please

    • @DotNetCoreCentral
      @DotNetCoreCentral  3 ปีที่แล้ว

      @Ha Nguyen, thanks for watching! I will definitely look into Envoy.

  • @tplummer217
    @tplummer217 2 ปีที่แล้ว

    Shouldn’t you always validate your audience?