title: Is single Request object instance in REST client okay?
body: <p>I'm writing a simple REST client for a C# WinForm application. I use <a href="http://restsharp.org/" rel="nofollow">RestSharp</a> to make sending requests and getting responses easier. I have a few questions regarding how I should design my client.</p>
  
  <p>The user interacts with the client only once. He pushes a <code>Button</code> and the client is instantiated and passed to <code>private</code> methods to do some logic in the background. It accesses objects from the server and synchronizes them with objects in the user's internal database.</p>
  
  <p>The point is that the client's methods are accessed by <code>private</code> methods called following the user's single action in the GUI. He does not have any control over which of the client's methods are called, and in which order.</p>
  
  <p>So my questions are:</p>
  
  <ul>
  <li><p>Can I ask the server for a token only once when I instantiate my client, and then store it in the client instance for future reference in the client's following requests? The token is a hash of the username and password, so it should not change over time. Of course, once I create a new instance of the client, it will again ask the server for a token.</p></li>
  <li><p>Is it okay to keep a single <code>Request</code> object instance in my client? I can then set request header only once and all the methods that access the API will only need to change the request's resource URL and HTTP method. It would reduce repetitiveness in my code. </p></li>
  </ul>
  
  <p>For example:</p>
  
  <pre><code>public PriceListItem[] GetPriceListItems()
  {
     string requestUrl = Resources.PriceListItemsUrl;
  
     var request = new RestRequest(requestUrl, Method.GET);
     request.AddHeader("SecureToken", _token);
  
     var response = Client.Execute(request) as RestResponse;
  
     JObject jObject = JObject.Parse(response.Content);
     var priceListItems = jObject["Data"].ToObject&lt;PriceListItem[]&gt;();
  
     return priceListItems;
  }
  </code></pre>
  
  <p>I have quite a few methods for utilizing different resource URLs, but all have the same header. If I keep only one <code>Request</code> instance in my client I can set the header only once. Is this approach okay? I would like to avoid any delegates and events.</p>