Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

added shortcuts to execute by method

  • Loading branch information...
commit d031be5d5a7a7ec95c079a630489d8f3e7256203 1 parent 9d11af9
John Sheehan johnsheehan authored

Showing 2 changed files with 170 additions and 0 deletions. Show diff stats Hide diff stats

  1. +86 0 RestSharp/RestClient.Async.cs
  2. +84 0 RestSharp/RestClient.Sync.cs
86 RestSharp/RestClient.Async.cs
@@ -107,5 +107,91 @@ public virtual RestRequestAsyncHandle ExecuteAsync<T>(IRestRequest request, Acti
107 107 callback(restResponse, asyncHandle);
108 108 });
109 109 }
  110 +
  111 + public virtual RestRequestAsyncHandle GetAsync<T>(IRestRequest request, Action<RestResponse<T>, RestRequestAsyncHandle> callback) where T : new()
  112 + {
  113 + request.Method = Method.GET;
  114 + return ExecuteAsync<T>(request, callback);
  115 + }
  116 +
  117 + public virtual RestRequestAsyncHandle PostAsync<T>(IRestRequest request, Action<RestResponse<T>, RestRequestAsyncHandle> callback) where T : new()
  118 + {
  119 + request.Method = Method.POST;
  120 + return ExecuteAsync<T>(request, callback);
  121 + }
  122 +
  123 + public virtual RestRequestAsyncHandle PutAsync<T>(IRestRequest request, Action<RestResponse<T>, RestRequestAsyncHandle> callback) where T : new()
  124 + {
  125 + request.Method = Method.PUT;
  126 + return ExecuteAsync<T>(request, callback);
  127 + }
  128 +
  129 + public virtual RestRequestAsyncHandle HeadAsync<T>(IRestRequest request, Action<RestResponse<T>, RestRequestAsyncHandle> callback) where T : new()
  130 + {
  131 + request.Method = Method.HEAD;
  132 + return ExecuteAsync<T>(request, callback);
  133 + }
  134 +
  135 + public virtual RestRequestAsyncHandle OptionsAsync<T>(IRestRequest request, Action<RestResponse<T>, RestRequestAsyncHandle> callback) where T : new()
  136 + {
  137 + request.Method = Method.OPTIONS;
  138 + return ExecuteAsync<T>(request, callback);
  139 + }
  140 +
  141 + public virtual RestRequestAsyncHandle PatchAsync<T>(IRestRequest request, Action<RestResponse<T>, RestRequestAsyncHandle> callback) where T : new()
  142 + {
  143 + request.Method = Method.PATCH;
  144 + return ExecuteAsync<T>(request, callback);
  145 + }
  146 +
  147 + public virtual RestRequestAsyncHandle DeleteAsync<T>(IRestRequest request, Action<RestResponse<T>, RestRequestAsyncHandle> callback) where T : new()
  148 + {
  149 + request.Method = Method.DELETE;
  150 + return ExecuteAsync<T>(request, callback);
  151 + }
  152 +
  153 +
  154 + public virtual RestRequestAsyncHandle GetAsync(IRestRequest request, Action<RestResponse, RestRequestAsyncHandle> callback)
  155 + {
  156 + request.Method = Method.GET;
  157 + return ExecuteAsync(request, callback);
  158 + }
  159 +
  160 + public virtual RestRequestAsyncHandle PostAsync(IRestRequest request, Action<RestResponse, RestRequestAsyncHandle> callback)
  161 + {
  162 + request.Method = Method.POST;
  163 + return ExecuteAsync(request, callback);
  164 + }
  165 +
  166 + public virtual RestRequestAsyncHandle PutAsync(IRestRequest request, Action<RestResponse, RestRequestAsyncHandle> callback)
  167 + {
  168 + request.Method = Method.PUT;
  169 + return ExecuteAsync(request, callback);
  170 + }
  171 +
  172 + public virtual RestRequestAsyncHandle HeadAsync(IRestRequest request, Action<RestResponse, RestRequestAsyncHandle> callback)
  173 + {
  174 + request.Method = Method.HEAD;
  175 + return ExecuteAsync(request, callback);
  176 + }
  177 +
  178 + public virtual RestRequestAsyncHandle OptionsAsync(IRestRequest request, Action<RestResponse, RestRequestAsyncHandle> callback)
  179 + {
  180 + request.Method = Method.OPTIONS;
  181 + return ExecuteAsync(request, callback);
  182 + }
  183 +
  184 + public virtual RestRequestAsyncHandle PatchAsync(IRestRequest request, Action<RestResponse, RestRequestAsyncHandle> callback)
  185 + {
  186 + request.Method = Method.PATCH;
  187 + return ExecuteAsync(request, callback);
  188 + }
  189 +
  190 + public virtual RestRequestAsyncHandle DeleteAsync(IRestRequest request, Action<RestResponse, RestRequestAsyncHandle> callback)
  191 + {
  192 + request.Method = Method.DELETE;
  193 + return ExecuteAsync(request, callback);
  194 + }
  195 +
110 196 }
111 197 }
84 RestSharp/RestClient.Sync.cs
@@ -70,6 +70,90 @@ public virtual RestResponse<T> Execute<T>(IRestRequest request) where T : new()
70 70 var raw = Execute(request);
71 71 return Deserialize<T>(request, raw);
72 72 }
  73 +
  74 + public virtual RestResponse<T> Get<T>(IRestRequest request) where T : new()
  75 + {
  76 + request.Method = Method.GET;
  77 + return Execute<T>(request);
  78 + }
  79 +
  80 + public virtual RestResponse<T> Post<T>(IRestRequest request) where T : new()
  81 + {
  82 + request.Method = Method.POST;
  83 + return Execute<T>(request);
  84 + }
  85 +
  86 + public virtual RestResponse<T> Put<T>(IRestRequest request) where T : new()
  87 + {
  88 + request.Method = Method.PUT;
  89 + return Execute<T>(request);
  90 + }
  91 +
  92 + public virtual RestResponse<T> Head<T>(IRestRequest request) where T : new()
  93 + {
  94 + request.Method = Method.HEAD;
  95 + return Execute<T>(request);
  96 + }
  97 +
  98 + public virtual RestResponse<T> Options<T>(IRestRequest request) where T : new()
  99 + {
  100 + request.Method = Method.OPTIONS;
  101 + return Execute<T>(request);
  102 + }
  103 +
  104 + public virtual RestResponse<T> Patch<T>(IRestRequest request) where T : new()
  105 + {
  106 + request.Method = Method.PATCH;
  107 + return Execute<T>(request);
  108 + }
  109 +
  110 + public virtual RestResponse<T> Delete<T>(IRestRequest request) where T : new()
  111 + {
  112 + request.Method = Method.DELETE;
  113 + return Execute<T>(request);
  114 + }
  115 +
  116 + public virtual RestResponse Get(IRestRequest request)
  117 + {
  118 + request.Method = Method.GET;
  119 + return Execute(request);
  120 + }
  121 +
  122 + public virtual RestResponse Post(IRestRequest request)
  123 + {
  124 + request.Method = Method.POST;
  125 + return Execute(request);
  126 + }
  127 +
  128 + public virtual RestResponse Put(IRestRequest request)
  129 + {
  130 + request.Method = Method.PUT;
  131 + return Execute(request);
  132 + }
  133 +
  134 + public virtual RestResponse Head(IRestRequest request)
  135 + {
  136 + request.Method = Method.HEAD;
  137 + return Execute(request);
  138 + }
  139 +
  140 + public virtual RestResponse Options(IRestRequest request)
  141 + {
  142 + request.Method = Method.OPTIONS;
  143 + return Execute(request);
  144 + }
  145 +
  146 + public virtual RestResponse Patch(IRestRequest request)
  147 + {
  148 + request.Method = Method.PATCH;
  149 + return Execute(request);
  150 + }
  151 +
  152 + public virtual RestResponse Delete(IRestRequest request)
  153 + {
  154 + request.Method = Method.DELETE;
  155 + return Execute(request);
  156 + }
73 157
74 158 private RestResponse GetResponse(IRestRequest request)
75 159 {

0 comments on commit d031be5

Please sign in to comment.
Something went wrong with that request. Please try again.