4

I've got some work to do for school around Microservices.

I've got the architectural concept, but need an implementation to show off. I'll be using angular2 as a client, would like to use a .NET core API gateway to dispatch my requests to different services.

What's the best approach for this? I red something about using Rx.Net, but no definitive example or implementation that I can follow.

So what should I do to implement an API gateway in .NET Core?

TanguyB
  • 1,954
  • 3
  • 21
  • 40
  • Don't ask for library recommendations on stack overflow. [link](http://stackoverflow.com/help/dont-ask) – galister Jan 24 '17 at 09:30
  • I'll edit it, thanks! – TanguyB Jan 24 '17 at 09:33
  • What kind of APIs are we talking about? HTTP? – galister Jan 24 '17 at 09:36
  • Yeah I'm thinking of making HTTP calls to the gateway, and this dispatches them to the correct service. – TanguyB Jan 24 '17 at 09:41
  • @galister like this: https://cdn.wp.nginx.com/wp-content/uploads/2016/04/Richardson-microservices-part2-3_api-gateway.png – TanguyB Jan 24 '17 at 09:41
  • @TanguyB You could actually use nginx for that too – poke Jan 24 '17 at 09:56
  • @I'll look into that thanks! – TanguyB Jan 24 '17 at 09:59
  • For your school project, do you want to build an API Gateway using .NET Core? Or you want to demonstrate some product/system with your JS/Angular/SPA based front-end talking to your Microservices via an API Gateway? If it is later, then you can select any API gateway which can run on your selected environment such as windows and just use it. – hB0 Jan 24 '17 at 19:57
  • I'd like to build an API gateway myself in .NET core. – TanguyB Jan 25 '17 at 08:28

2 Answers2

9

This may or may not help but I am currently building an API gateway in .NET core.

You can find it at https://github.com/TomPallister/Ocelot.

The code is a little ropey but a few people are working on it now so hopefully we can improve it over time.

TomPallister
  • 159
  • 1
  • 10
  • It is nice of you to answer. However this question is Off-Topic for StackOverflow, as `Questions asking us to recommend or find a book, tool, software library, tutorial or other off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam.` – Martin Verjans Apr 03 '17 at 09:28
  • 1
    I have been trying to use Ocelot, but I can't make it work :( I create a new project, I update all the libraries, install Ocelot, configure the ReRoutes, but when I run it, it stand just loading – Piyey Apr 26 '17 at 14:24
-1

You want to have a server that listens to the incoming API calls, e.g. a HttpListener.

Inside the handler of incoming requests, you peek into the request and decide where the API call needs to be relayed.

Then you use something like a HttpClient to make another request to the actual API endpoint (mimicking the original request as closely as possible) and you relay its response back to the user.

It should all be in the listener's request handler, and the response to the original request is the response from the real API.

See MSDN docs on HttpListener.

Also a good read: Handling multiple requests with C# HttpListener

Community
  • 1
  • 1
galister
  • 430
  • 3
  • 9