I've created a very simple REST microservice that receives information about an email and sends it. The microservice send method looks something like this:
//EmailController
[HttpPost]
public IHttpActionResult Send(Email email)
{
// send email via exchange
}
Now in my application, I call it using RestSharp like this:
var client = new RestClient("http://localhost:51467/api/");
var request = new RestRequest("email/send", Method.POST);
request.RequestFormat = DataFormat.Json;
dynamic obj = new ExpandoObject();
obj.FromAddress = from;
obj.ToAddress = to;
obj.Subject = subject;
obj.Body = body;
request.AddBody(obj);
client.Execute(request);
Questions I have:
Is this the best way to do the call? Obviously i'll later have to add error handling etc, but I'm talking more the way I'm using RestSharp to do the call.
I'm finding it a bit uncomfortable that my app needs to kind of know what object the microservice expects to receive - there's no sort of definition/interface/contract that it uses to know for sure. Is this generally accepted as being ok for REST or should I implement some sort of interface that my app has so it can call my microservice in a bit more of a defined way. Is that even something possible with REST?
Thanks for any help!
ASP.NET comes with built-in support for developing and deploying your microservices using Docker containers. . NET includes APIs to easily consume microservices from any application you build, including mobile, desktop, games, web, and more.
The most common type is single-receiver communication with a synchronous protocol like HTTP/HTTPS when invoking a regular Web API HTTP service. Microservices also typically use messaging protocols for asynchronous communication between microservices.
Microservices are small, modular, and independently deployable services. Docker containers (for Linux and Windows) simplify deployment and testing by bundling a service and its dependencies into a single unit, which is then run in an isolated environment.
REST services do not have a schema or WSDL type of function to define the format of the service. This is what makes them more light weight compared to traditional web services.
There is something called WADL, or Web Application Description Language, but this is not really a standard, and isn't widely supported. It's also quite controversial as there are many that feel it's not needed.
http://en.wikipedia.org/wiki/Web_Application_Description_Language
Also see this discussion on Programmers
https://softwareengineering.stackexchange.com/a/133693/4368
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