Building Simple API Gateways with Ocelot and ASP.net Core
In the previous article, we've discovered what is an API gateway and the cool things that it brings. This article will demonstrate how to build a simple API gateway that routes incoming HTTP requests to the appropriate downstream services.
Articles in the Series
This article belongs to a series of articles that explains the importance of API gateways and how to build them using ASP.net Core. If you're interested to learn more about API gateways, it might be a good idea to spend some time reading the articles listed below.- Part 1: API Gateway in a Nutshell.
- Part 2: Building Simple API Gateways with Ocelot.
- Part 3: API Response Aggregation using Ocelot
- Part 4: API Defense using Rate Limiting and Ocelot.
- Part 5: Containerizing API Gateways
- Part 6: Containerizing API Gateways using Alpine Base Image
Introducing Ocelot
Download POC from GithubOcelot is an open source framework used for building .NET core API gateways, the project is aimed at people using .NET / .NET Core to build applications designed with microservices or SOA architectures. Ocelot provides an easy way to write a mapping file (ocelot.json) that could be used to route incoming HTTP requests to the appropriate downstream services.
See: GITHUB | Official Website
Battle Plan
In this guide, we'll build an API gateway for an e-commerce website. The e-commerce API will contain three sub-domains that we'll call "Authentication", "Catalog" and "Ledger" contexts. The gateway we'll build in this article will behave like a reverse proxy that routes incoming HTTP requests to the following downstream services:
- Authentication Service - Bounded context in-charge of managing all authentication related things like end-users and access to system.
- Catalog Service - Bounded context in-charge of managing all offered products.
- Ledger Service - Bounded context in-charge of managing all monetary-product transactions in the system.
Setup
If you want to skip the setup phase, you can download a bunch of bash scripts that I wrote to automate the generation of the four ASP.net core projects. Once you've downloaded the scripts, place them in a folder to group the output of the automation process and execute the script named 100_build-api-gateway.sh.
If you are a newbie in ASP.net Core or just keen to learn how the setup works, you can follow the steps below:
-
Generate 4 ASP.net Core Projects
-
Generate Solution and Attach Projects
-
Install Ocelot Nuget Package
-
Generate POCOs and Controllers
You can navigate to a sample project from GITHUB and copy the following models and controllers to your solutions:-
User Model
./Authentication/Models/User.cs Github Link -
User Controller
./Authentication/Controllers/UserController.cs Github Link -
Product Model
./Catalog/Models/Product.cs Github Link -
Project Controller
./Catalog/Controllers/ProductController.cs Github Link -
Transaction Model
./Ledger/Models/Transaction.cs Github Link -
Transaction Contorller
./Ledger/Controllers/TransactionController.cs Github Link
-
-
Configure Service Ports via launchSettings.json
In order to route HTTP requests properly, you have to ensure that each service will be able to run on the following local ports:- Authentication: http://localhost:52792/
- Catalog: http://localhost:52791
- Ledger: http://localhost:52790
- Gateway: http://localhost:52793
-
Start and test individual bounded context services
Test the solutions by running each of them and issuing a GET request against the following URLS:- Authentication: http://localhost:52792/api/user
- Catalog: http://localhost:52791/api/product/
- Ledger: http://localhost:52790/api/transaction
Configuring Ocelot
Now lets focus on the most important detail which is configuring Ocelot. The first thing that we have to do is configure the ocelot.json file and add the code below. Note that the BaseUrl is required by Ocelot for it to be aware of the URL it is running in order to perform a header find & replace for certain administrative configurations.
Navigate to the Program.cs file of the Gateway project and add the following configurations on the web host builder method. The code below will setup all the middlewares required by ocelot to function.
Setting up your Routes
Now that everything we need in the gateway side is configured, its time to setup routes using the ocelot.json file. Update your ocelot.json file by updating the re-routes section. The code above setups up the mappings dictionary of (see below) your application gateway to the downstream services.
- Gateway to Authentication
- Gateway to Catalog
- Gateway to Ledger
Testing the routes out
To test the routes, start all projects and navigate to each link listed below.
- User Endpoint http://localhost:52793/api/user
- Products Endpoint http://localhost:52793/api/product
- Transaction Endpoint http://localhost:52793/api/transaction
Conclusion
In this article, we've learned how to perform basic re-routing of HTTP requests from a gateway to downstream services using Ocelot. Please do note that the article only explained basic re-routing and the power of API gateways starts to shine with request aggregation which is the subject of the next article.
Related Articles
- Part 1: API Gateway in a Nutshell.
- Part 2: Building Simple API Gateways with Ocelot.
- Part 3: API Response Aggregation using Ocelot
- Part 4: API Defense using Rate Limiting and Ocelot.
- Part 5: Containerizing API Gateways
- Part 6: Containerizing API Gateways using Alpine Base Image
- 10 Steps to Setup and Containerize an Express Server
- Microservices: Picking the .NET Framework for your containerized applications.
That is very interesting; you are a very skilled blogger. I have shared your website in my social networks! A very nice guide. I will definitely follow these tips. Thank you for sharing such detailed article.
ReplyDeleteBest Quoting Software
Thanks, this is generally helpful.
ReplyDeleteStill, I followed step-by-step your method in this
dot net online training
dot net online course
adana escort - adıyaman escort - afyon escort - aksaray escort - antalya escort - aydın escort - balıkesir escort - batman escort - bitlis escort - burdur escort - bursa escort - diyarbakır escort - edirne escort - erzurum escort - eskişehir escort - eskişehir escort - eskişehir escort - eskişehir escort - gaziantep escort - gebze escort - giresun escort - hatay escort - ısparta escort - karabük escort - kastamonu escort - kayseri escort - kilis escort - kocaeli escort - konya escort - kütahya escort - malatya escort - manisa escort - maraş escort - mardin escort - mersin escort - muğla escort - niğde escort - ordu escort - osmaniye escort - sakarya escort - samsun escort - siirt escort - sincan escort - tekirdağ escort - tokat escort - uşak escort - van escort - yalova escort - yozgat escort - urfa escort - zonguldak escort
ReplyDeleteadanaescort01.com - adiyamanescortxx.com - afyonarackiralama.net - aksarayescort.net - antalyaoyunpark.com - aydinescortkiz.com - balikesirescortlar.com - batmanescortlar.com - bitlisescortlar.com - burdurescortlar.com - bursamalaysias.com - diyarbakirambar.com - edirnedespor.com - erzurumyolkosusu.com - eskisehirescortlari.com - gaziantepekspres.org - gebzeescortkiz.com - giresunmaraton.com - hataykoleji.com - ispartakpss.com - karabukteknik.com - kastamonuajans.net - kayserivalisi.com - kilisescort.com - kocaeliescortlar.com - konyaescortlar.com - kutahyaizemlak.com - malatyadataksi.com - manisaescortlar.com - marasatasoyemlak.com - mardinfanatik.com - mersinmoda.com - muglaapart.net - nigdeyapi.com - orduescortt.com - osmaniyeyorum.com - sakaryanur.com - samsunescortlar.com - siirteyatirim.com - sincanoto.com - tekirdagescortlar.com - tokatforum.com - usakbasin.com - vanescortilan.com - yalovadaemlak.com - yozgattanal.com - sanliurfadayim.com - zonguldakescort.com
ReplyDeleteno deposit bonus forex 2021 - takipçi satın al - takipçi satın al - takipçi satın al - tiktok takipçi satın al - instagram beğeni satın al - instagram beğeni satın al - google haritalara yer ekleme - btcturk - tiktok izlenme satın al - sms onay - izlenme-satin-al.com/youtube - google haritalara yer ekleme - no deposit bonus forex 2021 - tiktok jeton hilesi - tiktok beğeni satın al - binance - takipçi satın al - uc satın al - finanspedia.com - sms onay - sms onay - tiktok takipçi satın al - tiktok beğeni satın al - twitter takipçi satın al - trend topic satın al - youtube abone satın al - instagram beğeni satın al - tiktok beğeni satın al - twitter takipçi satın al - trend topic satın al - youtube abone satın al - instagram beğeni satın al - tiktok takipçi satın al - tiktok beğeni satın al - twitter takipçi satın al - trend topic satın al - youtube abone satın al - instagram beğeni satın al - perde modelleri - instagram takipçi satın al - instagram takipçi satın al
ReplyDeleteinstagram takipçi satın al
ReplyDeleteinstagram takipçi satın al
takipçi satın al
instagram takipçi satın al
instagram takipçi satın al
takipçi satın al
instagram takipçi satın al
aşk kitapları
tiktok takipçi satın al
instagram beğeni satın al
youtube abone satın al
twitter takipçi satın al
tiktok beğeni satın al
tiktok izlenme satın al
twitter takipçi satın al
tiktok takipçi satın al
youtube abone satın al
tiktok beğeni satın al
instagram beğeni satın al
trend topic satın al
trend topic satın al
youtube abone satın al
beğeni satın al
tiktok izlenme satın al
sms onay
youtube izlenme satın al
tiktok beğeni satın al
sms onay
sms onay
perde modelleri
instagram takipçi satın al
takipçi satın al
tiktok jeton hilesi
pubg uc satın al
sultanbet
marsbahis
betboo
betboo
betboo
kayseri escort - hatay escort - kayseri escort
ReplyDeleteinstagram takipçi satın al
ReplyDeleteucuz takipçi
takipçi satın al
https://takipcikenti.com
https://ucsatinal.org
instagram takipçi satın al
https://perdemodelleri.org
https://yazanadam.com
instagram takipçi satın al
balon perdeler
petek üstü perde
mutfak tül modelleri
kısa perde modelleri
fon perde modelleri
tül perde modelleri
https://atakanmedya.com
https://fatihmedya.com
https://smmpaketleri.com
https://takipcialdim.com
https://yazanadam.com
yasaklı sitelere giriş
aşk kitapları
yabancı şarkılar
sigorta sorgula
https://cozumlec.com
word indir ücretsiz
tiktok jeton hilesi
rastgele görüntülü sohbet
erkek spor ayakkabı
fitness moves
gym workouts
https://marsbahiscasino.org
http://4mcafee.com
http://paydayloansonlineare.com
toptan iç giyim tercih etmenizin sebebi kaliteyi ucuza satın alabilmektir. Ürünler yine orjinaldir ve size sorun yaşatmaz. Yine de bilinen tekstil markalarını tercih etmelisiniz.
ReplyDeleteDigitürk başvuru güncel adresine hoşgeldiniz. Hemen başvuru yaparsanız anında kurulum yapmaktayız.
tutku iç giyim Türkiye'nin önde gelen iç giyim markalarından birisi olmasının yanı sıra en çok satan markalardan birisidir. Ürünleri hem çok kalitelidir hem de pamuk kullanımı daha fazladır.
nbb sütyen hem kaliteli hem de uygun fiyatlı sütyenler üretmektedir. Sütyene ek olarak sütyen takımı ve jartiyer gibi ürünleri de mevcuttur. Özellikle Avrupa ve Orta Doğu'da çokça tercih edilmektedir.
yeni inci sütyen kaliteyi ucuz olarak sizlere ulaştırmaktadır. Çok çeşitli sütyen varyantları mevcuttur. iç giyime damga vuran markalardan biridir ve genellikle Avrupa'da ismi sıklıkla duyulur.
iç giyim ürünlerine her zaman dikkat etmemiz gerekmektedir. Üretimde kullanılan malzemelerin kullanım oranları, kumaşın esnekliği, çekmezlik testi gibi birçok unsuru aynı anda değerlendirerek seçim yapmalıyız.
iç giyim bayanların erkeklere göre daha dikkatli oldukları bir alandır. Erkeklere göre daha özenli ve daha seçici davranırlar. Biliyorlar ki iç giyimde kullandıkları şeyler kafalarındaki ve ruhlarındaki özellikleri dışa vururlar.
takipçi satın al
ReplyDeletetakipçi satın al
takipçi satın al
Ah, there is a good discussion about this paragraph on this website at this place, I read all that, so now I am commenting here too... Qualified travelers can get a Turkey visa by filling an online fill visa application to Turkey can do.
ReplyDeleteI think you should make a video how to build it and share such video on youtube. If you use this site https://soclikes.com you can promote your video faster
ReplyDeleteVery informative. I advice you to post this article as a video-review on Youtube so that many interested people can see it. And you can always use the services of https://viplikes.net/buy-youtube-subscribers to increase their number.
ReplyDeleteYou made some good points there. I searched on google about this topic and found that most of the people will believe your blog… Eligible citizens can apply for a kenya e-visa through a simple online application form to obtain an approved e-Visa electronically linked to their passport.
ReplyDeleteThanks for sharing excellent information.keep sharing such useful information..You can apply Indian business visa application through Online indian evisa website.
ReplyDeleteVery nice post, I definitely love this website, keep up the good work.. yes. Azerbaijan visa for US citizens can be acquired in a breeze with the convenience of online Azerbaijan Visa application processes. The Azerbaijan government has launched a new online visa system, wherein you can fill an application and receive your Azerbaijan visa entirely online .
ReplyDeleteeskişehir
ReplyDeleteizmir
muğla
yalova
çanakkale
düzce
antalya
aydın
mate
I love to read this, thank you... Indian visa online for US citizens, You can apply online completely securely through eVisa India website. The government of India has announced that travelers with tourist visas are now allowed to stay in India for a maximum period of 30 days.
ReplyDeleteDigital commerce, also known as e-commerce , is indeed a business concept that allows businesses and individuals to buy and sell goods through the Internet. The growth of online developers in India has been fueled by advancements in the IT industry and increased consumer understanding of the Internet.
ReplyDeletePPC company in India
PPC Company in USA
Exellent your post. i reaching daily on your blogs. thanks for sharing this informative information.
ReplyDeleteBuy YouTube Views
Buy YouTube Subscribers
Buy YouTube Live Stream Views
Buy Facebook Live Views
Buy Instagram Reels Views
Buy Instagram Live Views
Buy Instagram Followers
Buy Facebook Views
Buy 500 YouTube Views
Thanks for this post. Foreign travelers who wish to apply for Azerbaijan visa must check the requirements for azerbaijan visa before filling the application.
ReplyDeleteWow, that's what I was looking for, what stuff! Present here on this website, thanks to the admin of this website.. how to apply for Turkish visa, You can apply online for a Turkish e visa.
ReplyDeleteHii,
ReplyDeleteThis is Great Post.. for me, Thanks for sharing with us!!
Buy Real Facebook Live Stream Views
Buy Facebook Comments
Buy Facebook Video Views
Hello sir, Hope your evening is going well. Do you need an evisa to India? You can find more information about e visa to India on our website about India e visa.
ReplyDeleteseo fiyatları
ReplyDeletesaç ekimi
dedektör
instagram takipçi satın al
ankara evden eve nakliyat
fantezi iç giyim
sosyal medya yönetimi
mobil ödeme bozdurma
kripto para nasıl alınır
bitcoin nasıl alınır
ReplyDeletetiktok jeton hilesi
youtube abone satın al
gate io güvenilir mi
referans kimliği nedir
tiktok takipçi satın al
bitcoin nasıl alınır
mobil ödeme bozdurma
mobil ödeme bozdurma
The information you provided in your article is nice. I am satisfied with how well you have explained this subject. It is a useful article for us. For those of you around the world who wish to travel to Myanmar, there is good news - Myanmar visas have been opened & If you want to know the Myanmar eVisa Fee here is a wonderful site where you get information about fees from your country.
ReplyDeleteHello friends, Indian visa for US citizens, Indian e-Visa is issued for USA citizens under the following 5 categories. More info about Indian visas you can read through our website.
ReplyDeleteperde modelleri
ReplyDeletesms onay
mobil ödeme bozdurma
nft nasıl alınır
ANKARA EVDEN EVE NAKLİYAT
Trafik Sigortası
dedektor
KURMA WEB SİTESİ
Aşk Romanları
bostansepeti.com
ReplyDeletesite kurma
ürünler
vezirsosyalmedya.com
postegro
sosyal medya yönetimi
surucukursuburada.com
patent sorgula
ReplyDeleteyorumbudur.com
yorumlar
tiktok jeton hilesi
mobil ödeme bozdurma
mobil ödeme bozdurma
mobil ödeme bozdurma
pubg uc satın al
pubg uc satın al
Euro Palace complies with rules from Malta Gaming Authority, making it some of the secure on-line slots sites. It additionally provides versatile banking choices and simplistic slot designs to create an gratifying experience for each player, no matter their playing experience. To assist you to determine, we did the analysis and found the eight greatest on-line slots in Canada. We rated every on-line casino beneath on a variety of|quite so much of|a big selection of} components together with welcome bonus, choice of games, return-to-player , sport software program, banking choices, and user critiques. Naturally, the first thing we looked for was whether or not 카지노사이트 you can to|you presumably can} play free on-line slots.
ReplyDelete