Skip to content

Commit 89ede11

Browse files
authored
Merge pull request #185 from neegool/feature/add_patch_keyword
Add support for PATCH verb
2 parents bdc9d6f + 4d76af7 commit 89ede11

File tree

2 files changed

+140
-0
lines changed

2 files changed

+140
-0
lines changed

src/Proyecto26.RestClient/RestClient.cs

+69
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,75 @@ public static void Put<T>(RequestHelper options, Action<RequestException, Respon
342342
Request(options, callback);
343343
}
344344

345+
/// <summary>
346+
/// Load data from the server using a HTTP PATCH request.
347+
/// </summary>
348+
/// <param name="url">A string containing the URL to which the request is sent.</param>
349+
/// <param name="body">A plain object that is sent to the server with the request.</param>
350+
/// <param name="callback">A callback function that is executed when the request is finished.</param>
351+
public static void Patch(string url, object body, Action<RequestException, ResponseHelper> callback)
352+
{
353+
Patch(new RequestHelper { Uri = url, Body = body }, callback);
354+
}
355+
356+
/// <summary>
357+
/// Load data from the server using a HTTP PATCH request.
358+
/// </summary>
359+
/// <param name="url">A string containing the URL to which the request is sent.</param>
360+
/// <param name="bodyString">A string that is sent to the server with the request.</param>
361+
/// <param name="callback">A callback function that is executed when the request is finished.</param>
362+
public static void Patch(string url, string bodyString, Action<RequestException, ResponseHelper> callback)
363+
{
364+
Patch(new RequestHelper { Uri = url, BodyString = bodyString }, callback);
365+
}
366+
367+
/// <summary>
368+
/// Load data from the server using a HTTP PATCH request.
369+
/// </summary>
370+
/// <param name="options">The options of the request.</param>
371+
/// <param name="callback">A callback function that is executed when the request is finished.</param>
372+
public static void Patch(RequestHelper options, Action<RequestException, ResponseHelper> callback)
373+
{
374+
options.Method = "PATCH";
375+
Request(options, callback);
376+
}
377+
378+
/// <summary>
379+
/// Load data from the server using a HTTP PATCH request.
380+
/// </summary>
381+
/// <param name="url">A string containing the URL to which the request is sent.</param>
382+
/// <param name="body">A plain object that is sent to the server with the request.</param>
383+
/// <param name="callback">A callback function that is executed when the request is finished.</param>
384+
/// <typeparam name="T">The element type of the response.</typeparam>
385+
public static void Patch<T>(string url, object body, Action<RequestException, ResponseHelper, T> callback)
386+
{
387+
Patch<T>(new RequestHelper { Uri = url, Body = body }, callback);
388+
}
389+
390+
/// <summary>
391+
/// Load data from the server using a HTTP PATCH request.
392+
/// </summary>
393+
/// <param name="url">A string containing the URL to which the request is sent.</param>
394+
/// <param name="bodyString">A string that is sent to the server with the request.</param>
395+
/// <param name="callback">A callback function that is executed when the request is finished.</param>
396+
/// <typeparam name="T">The element type of the response.</typeparam>
397+
public static void Patch<T>(string url, string bodyString, Action<RequestException, ResponseHelper, T> callback)
398+
{
399+
Patch<T>(new RequestHelper { Uri = url, BodyString = bodyString }, callback);
400+
}
401+
402+
/// <summary>
403+
/// Load data from the server using a HTTP PATCH request.
404+
/// </summary>
405+
/// <param name="options">The options of the request.</param>
406+
/// <param name="callback">A callback function that is executed when the request is finished.</param>
407+
/// <typeparam name="T">The element type of the response.</typeparam>
408+
public static void Patch<T>(RequestHelper options, Action<RequestException, ResponseHelper, T> callback)
409+
{
410+
options.Method = "PATCH";
411+
Request(options, callback);
412+
}
413+
345414
/// <summary>
346415
/// Delete the specified resource identified by the URI.
347416
/// </summary>

src/Proyecto26.RestClient/RestClientPromise.cs

+71
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,77 @@ public static IPromise<T> Put<T>(RequestHelper options)
281281
return promise;
282282
}
283283

284+
/// <summary>
285+
/// Load data from the server using a HTTP PATCH request.
286+
/// </summary>
287+
/// <returns>Returns a promise for a value of type ResponseHelper.</returns>
288+
/// <param name="url">A string containing the URL to which the request is sent.</param>
289+
/// <param name="body">A plain object that is sent to the server with the request.</param>
290+
public static IPromise<ResponseHelper> Patch(string url, object body)
291+
{
292+
return Patch(new RequestHelper { Uri = url, Body = body });
293+
}
294+
295+
/// <summary>
296+
/// Load data from the server using a HTTP PATCH request.
297+
/// </summary>
298+
/// <returns>Returns a promise for a value of type ResponseHelper.</returns>
299+
/// <param name="url">A string containing the URL to which the request is sent.</param>
300+
/// <param name="bodyString">A string that is sent to the server with the request.</param>
301+
public static IPromise<ResponseHelper> Patch(string url, string bodyString)
302+
{
303+
return Patch(new RequestHelper { Uri = url, BodyString = bodyString });
304+
}
305+
306+
/// <summary>
307+
/// Load data from the server using a HTTP PATCH request.
308+
/// </summary>
309+
/// <returns>Returns a promise for a value of type ResponseHelper.</returns>
310+
/// <param name="options">The options of the request.</param>
311+
public static IPromise<ResponseHelper> Patch(RequestHelper options)
312+
{
313+
var promise = new Promise<ResponseHelper>();
314+
Patch(options, promise.Promisify);
315+
return promise;
316+
}
317+
318+
/// <summary>
319+
/// Load data from the server using a HTTP PATCH request.
320+
/// </summary>
321+
/// <returns>Returns a promise for a value of a specified type.</returns>
322+
/// <param name="url">A string containing the URL to which the request is sent.</param>
323+
/// <param name="body">A plain object that is sent to the server with the request.</param>
324+
/// <typeparam name="T">The element type of the response.</typeparam>
325+
public static IPromise<T> Patch<T>(string url, object body)
326+
{
327+
return Patch<T>(new RequestHelper { Uri = url, Body = body });
328+
}
329+
330+
/// <summary>
331+
/// Load data from the server using a HTTP PATCH request.
332+
/// </summary>
333+
/// <returns>Returns a promise for a value of a specified type.</returns>
334+
/// <param name="url">A string containing the URL to which the request is sent.</param>
335+
/// <param name="bodyString">A string that is sent to the server with the request.</param>
336+
/// <typeparam name="T">The element type of the response.</typeparam>
337+
public static IPromise<T> Patch<T>(string url, string bodyString)
338+
{
339+
return Patch<T>(new RequestHelper { Uri = url, BodyString = bodyString });
340+
}
341+
342+
/// <summary>
343+
/// Load data from the server using a HTTP PATCH request.
344+
/// </summary>
345+
/// <returns>Returns a promise for a value of a specified type.</returns>
346+
/// <param name="options">The options of the request.</param>
347+
/// <typeparam name="T">The element type of the response.</typeparam>
348+
public static IPromise<T> Patch<T>(RequestHelper options)
349+
{
350+
var promise = new Promise<T>();
351+
Patch<T>(options, promise.Promisify);
352+
return promise;
353+
}
354+
284355
/// <summary>
285356
/// Delete the specified resource identified by the URI.
286357
/// </summary>

0 commit comments

Comments
 (0)