.NET Core API Gateway [closed] - c#

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
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?

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.

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

Related

What is some of the most common ways to consume REST API's in a .NET environment? C# or JS or another language? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 2 years ago.
Improve this question
Would it be best to consume a REST API using Javascript, AngularJS, TypeScript or just straightup using C# to consume the REST API.
I'm new to the REST API game and want to know, because I see so many ways to consume and I would like to know some of the most common ways. In particular is it better to use JAVASCRIPT or ANGULARJS to Consume a REST API and then pass it to C# code to work with or not?
ANY straight forward literature would be appreciated. For example how to consume a LINKED API using REST or consume FACEBOOK API using REST. Some sort of straight forward guide.
I'm going to quote Margin Call(2011) "Talk to me as if I am a golden retriever because I can assure you I did not get in the position I am today by being smart".
So REST is a style of “implementation” and you can consume it anyhow i.e. You don’t consume Web api “using” REST, you implement it using REST.
There is no good or bad here. If all you have to do is consume the API and do something in your c# app then I would just use the http client in your c# app. And you can use any language/framework not just c#/.net/angular, it just depends on your preference. Behind the scenes it’s just http calls.
Every framework/language has its own best practices for consuming REST.
As far as literature is concerned, you would find a lot of material online to understand REST principles.
But do note that they are design guidelines, not following some of them does not make your web api any lesser REST.
So you ll find differences in the implementation of different REST web apis. And that is why there is a always a doc usually that guides how to consume it, either a swagger style documentation or something custom.
Hope this gives you the 1000 feet overview to get yourself started on the right track.
Some good tools that you should have:
Postman
Fiddler

How to call http azure functions via http requests in asp.net core? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I have one HTTP Post API (build in ASP.NET Core), that API is responsible to add Customer in database.I would like to send an email using Azure function at the time of HTTP Post request. Azure function should automatically get triggered. How to achieve this?
Why is it important to you that this is achieved by an Azure function? Azure Logic Apps were designed with such workflows in mind.
However, if it's important to you that this is implemented by an Azure Function then you'll need to create a new Azure Function with a Http Trigger. You'll need to implement the e-mail sending functionality yourself using a library such as MailKit.
Here's a good resource on using MailKit to send e-mails.

How best to communicate between two ASP.NET Core server apps? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I have two ASP.NET Core web apps (on different physical servers), and both use EF Core. Although both are "servers", one also collects data from the other (i.e. one of them is also a "client").
ASP.NET Core is different because there is no "MVC" and "WebAPI", it combines both. I'm not sure what new APIs to use.
How should I transfer data from one to the other?
My initial thought is the "client" app has an authenticated and authorized GET action which returns the data. But how? Can it directly return an EF entity, or am I responsible for serialization to/from JSON? Should it return IActionResult or something else? Should it be a regular or AJAX request? Is OWIN related to this somehow?
Is there any smart technique which is now available with ASP.NET Core? I don't need a solution, just some pointers in the right direction.
While the framework may have new helper methods/objects/etc. here or there, nothing's really changed regarding HTTP communication between a client and a server. Indeed, from the perspective of the client, there's no difference in the server regardless of what technology is used under the hood.
Can it directly return an EF entity
It sure can, just as Web API has in the past. Something as simple as:
public Widget Get(int id)
{
return _widgetRepository.Get(id);
}
(Assuming an implementation of a repository of some sort here, but you get the idea.)
The default HTTP response for this is generally a JSON-formatted response body and a 200 OK response code. You can have more control over that with a variety of framework helpers, there's a decent overview and introduction to a couple of them here.
Regardless of how you return any given result from the server, the client is still getting an HTTP response like any other. Codes, headers, content, etc.

.NET Server Sent Events with Reactive Extensions [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I'm trying to implement SSE (Server Sent Events) model with client an IHM in HTML5/JS and server side C#. I'm using a COTS that implements a event driven http server with Reactive Extensions in .NET.
Client SIDE
var evtSource = new EventSource("http://127.0.0.1:4444");
source.onmessage = function(event)
{
document.getElementById("result").innerHTML += event.data + "<br>";
};
1.The browser tolds me "Cross-Origin Request" has been refused. I'm on the same domain, is it normal?
2.Is it possible to adapt this http server to do SSE? If this is not possible, do you know some .NET libs (no copyleft) implementing SSE server side?
Thanks for your consideration.
The cross-origin can be fixed by adding "Origin:*" tot the headers. This can be done in different places depending on your architecture. With MVC it can be set in the global.asax. When using owin auth you can set it where you configure the authentication with this line: config.EnableCors(); I'm sure there is a lot to find when googling 'cross-origin'.
I'm not familiar with SSE. But if it is not working out for you you can check out SignalR.(http://www.asp.net/signalr/overview/guide-to-the-api/hubs-api-guide-net-client)
I found it very easy to implement when i was building a website with chat functionality.

Incoming SMS to trigger code in an MVC application [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
Im in the process of developing a CRM where, a client can send an SMS and trigger some event driven code to update a database. Ive been looking at Twilio pretty hard, and looked at all their documentation and none of their API documentation covers this particular context.
Can anyone help?
When you setup a Twilio SMS number, you configure an HTTP location for Twilio to POST or GET in response to an SMS message. You would build a service such as Web API to handle the XML that Twilio would post/get against your endpoint and do whatever your want on your database.
Here's a reference to the Twilio .NET/C# quick start for SMS. Your endpoint will get called when the SMS is received. You can return a basic XML document () or add xml elements that tell Twilio what to do, such as reply with another SMS. Twilio calls this "TwiML". Regardless, you'll get enough details to update your DB and do whatever else you might want to do.
Link to Quick Start: https://www.twilio.com/docs/quickstart/csharp/sms/hello-monkey

Categories