title: How to call a microservice in .NET
body: <p>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:</p>
  
  <pre><code>//EmailController
  [HttpPost]
  public IHttpActionResult Send(Email email)
  {
      // send email via exchange
  }
  </code></pre>
  
  <p>Now in my application, I call it using RestSharp like this:</p>
  
  <pre><code>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);
  </code></pre>
  
  <p>Questions I have:</p>
  
  <ol>
  <li><p>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.</p></li>
  <li><p>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?</p></li>
  </ol>
  
  <p>Thanks for any help!</p>