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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With