-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #38 from hanssens/vnext
Preparing for release v2.1.0
- Loading branch information
Showing
7 changed files
with
189 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using System.Collections.Generic; | ||
using System.Net.Http; | ||
using System.Threading.Tasks; | ||
|
||
namespace Hanssens.Net.Http | ||
{ | ||
public partial class HttpFactory | ||
{ | ||
public async Task<HttpResponseMessage> DeleteAsync(string requestUri, Dictionary<string, string> headers = null) | ||
{ | ||
// TODO: investigate the proper use of a 'body' in a DELETE operation | ||
// see also: http://stackoverflow.com/questions/299628/is-an-entity-body-allowed-for-an-http-delete-request | ||
return await Execute(HttpMethod.Delete, requestUri, body: string.Empty, headers: null); | ||
} | ||
|
||
public async Task<HttpResponseMessage> GetAsync(string requestUri, Dictionary<string, string> headers = null) | ||
{ | ||
return await Execute(HttpMethod.Get, requestUri, body: string.Empty, headers: headers); | ||
} | ||
|
||
public async Task<HttpResponseMessage> PatchAsync<T>(string requestUri, T body, Dictionary<string, string> headers = null) | ||
{ | ||
return await Execute(new HttpMethod("PATCH"), requestUri, body, headers); | ||
} | ||
|
||
public async Task<HttpResponseMessage> PostAsync<T>(string requestUri, T body, Dictionary<string, string> headers = null) | ||
{ | ||
return await Execute(HttpMethod.Post, requestUri, body, headers); | ||
} | ||
|
||
public async Task<HttpResponseMessage> PutAsync<T>(string requestUri, T body, Dictionary<string, string> headers = null) | ||
{ | ||
return await Execute(HttpMethod.Put, requestUri, body, headers); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
using System.Collections.Generic; | ||
using System.Net.Http; | ||
using System.Threading.Tasks; | ||
|
||
namespace Hanssens.Net.Http | ||
{ | ||
public partial class HttpFactory | ||
{ | ||
/// <summary> | ||
/// Provides 'simple', shorthand functions intended for quickly making a single http call. | ||
/// </summary> | ||
public static class Simple | ||
{ | ||
private static readonly HttpFactory Factory; | ||
|
||
static Simple() | ||
{ | ||
Factory = new HttpFactory(); | ||
} | ||
|
||
public static HttpResponseMessage Delete(string requestUri, Dictionary<string, string> headers = null) | ||
{ | ||
return Factory.DeleteAsync(requestUri, headers).Result; | ||
} | ||
|
||
public static async Task<HttpResponseMessage> DeleteAsync(string requestUri, Dictionary<string, string> headers = null) | ||
{ | ||
return await Factory.DeleteAsync(requestUri, headers); | ||
} | ||
|
||
/// <summary> | ||
/// Executes a single 'GET' request. | ||
/// </summary> | ||
/// <param name="requestUri">Endpoint to the remote resource</param> | ||
public static HttpResponseMessage Get(string requestUri) | ||
{ | ||
return Factory.Get(requestUri); | ||
} | ||
|
||
/// <summary> | ||
/// Executes a single async 'GET' request. | ||
/// </summary> | ||
/// <param name="requestUri">Endpoint to the remote resource</param> | ||
public static async Task<HttpResponseMessage> GetAsync(string requestUri, Dictionary<string, string> headers = null) | ||
{ | ||
return await Factory.GetAsync(requestUri, headers); | ||
} | ||
|
||
public static HttpResponseMessage Patch<T>(string requestUri, T body) where T : class | ||
{ | ||
return Factory.Patch(requestUri, body); | ||
} | ||
|
||
public static async Task<HttpResponseMessage> PatchAsync<T>(string requestUri, T body) where T : class | ||
{ | ||
return await Factory.PatchAsync(requestUri, body); | ||
} | ||
|
||
public static HttpResponseMessage Post<T>(string requestUri, T body) where T : class | ||
{ | ||
return Factory.Post(requestUri, body); | ||
} | ||
|
||
public static async Task<HttpResponseMessage> PostAsync<T>(string requestUri, T body) where T : class | ||
{ | ||
return await Factory.PostAsync(requestUri, body); | ||
} | ||
|
||
public static HttpResponseMessage Put<T>(string requestUri, T body) where T : class | ||
{ | ||
return Factory.Put(requestUri, body); | ||
} | ||
|
||
public static async Task<HttpResponseMessage> PutAsync<T>(string requestUri, T body) where T : class | ||
{ | ||
return await Factory.PutAsync(requestUri, body); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using System.Collections.Generic; | ||
using System.Net.Http; | ||
|
||
namespace Hanssens.Net.Http | ||
{ | ||
public partial class HttpFactory | ||
{ | ||
public HttpResponseMessage Delete(string requestUri, Dictionary<string, string> headers = null) | ||
{ | ||
return DeleteAsync(requestUri, headers).Result; | ||
} | ||
|
||
public HttpResponseMessage Get(string requestUri, Dictionary<string, string> headers = null) | ||
{ | ||
return GetAsync(requestUri, headers).Result; | ||
} | ||
|
||
public HttpResponseMessage Patch<T>(string requestUri, T body, Dictionary<string, string> headers = null) | ||
{ | ||
return PatchAsync(requestUri, body: body, headers: headers).Result; | ||
} | ||
|
||
public HttpResponseMessage Post<T>(string requestUri, T body, Dictionary<string, string> headers = null) | ||
{ | ||
return PostAsync(requestUri, body: body, headers: headers).Result; | ||
} | ||
|
||
public HttpResponseMessage Put<T>(string requestUri, T body, Dictionary<string, string> headers = null) | ||
{ | ||
return PutAsync(requestUri, body: body, headers: headers).Result; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Net.Http; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Hanssens.Net.Http | ||
{ | ||
public static class HttpResponseMessageExtensions | ||
{ | ||
/// <summary> | ||
/// Extension allowing easy access to get the value from a HttpResponseMessage. | ||
/// </summary> | ||
public static string Value(this HttpResponseMessage httpResponse) | ||
{ | ||
var response = httpResponse.Content.ReadAsStringAsync().Result; | ||
return response; | ||
} | ||
|
||
/// <summary> | ||
/// Extension allowing easy access to get the value from a HttpResponseMessage. | ||
/// </summary> | ||
public static async Task<string> ValueAsync(this HttpResponseMessage httpResponse) | ||
{ | ||
return await httpResponse.Content.ReadAsStringAsync(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters