-
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.
- Loading branch information
1 parent
883a006
commit 1699696
Showing
21 changed files
with
1,300 additions
and
20 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,7 @@ | |
[Rr]eleases/ | ||
[Xx]64/ | ||
[Xx]86/ | ||
[Bb]uild/ | ||
#[Bb]uild/ | ||
bld/ | ||
[Bb]in/ | ||
[Oo]bj/ | ||
|
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,5 @@ | ||
# Tavis.HttpResponseMachine # | ||
|
||
##0.9.0-beta | ||
- Initial release outside of Hapikit | ||
|
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 was deleted.
Oops, something went wrong.
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 @@ | ||
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0" DefaultTargets="default"> | ||
<PropertyGroup> | ||
<BaseDir>$(MSBuildProjectDirectory)\..</BaseDir> | ||
<Configuration Condition="'$(Configuration)'==''" >Release</Configuration> | ||
<ArtifactsDir>$(BaseDir)\artifacts</ArtifactsDir> | ||
<BuildDir>$(BaseDir)\build</BuildDir> | ||
<PackageDir>$(BuildDir)\Packages</PackageDir> | ||
|
||
<Project>HttpResponseMachine</Project> | ||
<ProjectFilePCL>$(BaseDir)\src\$(Project)\$(Project).csproj</ProjectFilePCL> | ||
<OutputDir>$(BaseDir)\src\$(Project)\bin\$(Configuration)</OutputDir> | ||
<SolutionDir>$(BaseDir)</SolutionDir> <!-- Needed or import of nuget targets in csproj file fails--> | ||
</PropertyGroup> | ||
|
||
|
||
<Target Name="default" DependsOnTargets="Compile; Package" /> | ||
|
||
<Target Name="Compile"> | ||
<MSBuild Projects="$(ProjectFilePCL)" | ||
Properties="Configuration=$(Configuration);SolutionDir=$(SolutionDir);OutputPath=$(ArtifactsDir)\$(Project)\lib\portable-net45+netcore45+wpa81" /> | ||
|
||
</Target> | ||
|
||
<Target Name="Package"> | ||
|
||
<Exec WorkingDirectory="$(BuildDir)" | ||
Command="nuget.exe pack $(BuildDir)\Tavis.$(Project).nuspec -OutputDirectory $(ArtifactsDir) " /> | ||
</Target> | ||
</Project> |
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,20 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd"> | ||
<metadata> | ||
<id>Tavis.HttpResponseMachine</id> | ||
<version>0.9.0-beta</version> | ||
<authors>Darrel Miller</authors> | ||
<owners>Darrel Miller</owners> | ||
<projectUrl>https://github.com/tavis-software/Tavis.HttpResponseMachine</projectUrl> | ||
<requireLicenseAcceptance>false</requireLicenseAcceptance> | ||
<description>Declarative binding of HTTP Response handlers</description> | ||
<releaseNotes> | ||
<![CDATA[ | ||
For full release notes see https://github.com/tavis-software/Tavis.HttpResponseMachine/blob/master/ReleaseNotes.md | ||
]]> | ||
</releaseNotes> | ||
</metadata> | ||
<files> | ||
<file src="..\artifacts\HttpResponseMachine\lib\**\Tavis.HttpResponseMachine.dll" target="lib" /> | ||
</files> | ||
</package> |
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,41 @@ | ||
# Tavis.HttpResponseMachine | ||
|
||
This library provides a declarative way of handling HTTP responses. | ||
|
||
|
||
Responses can be dispatched based on status code, media type and link relation type. | ||
|
||
machine.When(HttpStatusCode.OK, null, new MediaTypeHeaderValue("application/json")) | ||
.Then(async (l, r) => | ||
{ | ||
var text = await r.Content.ReadAsStringAsync(); | ||
root = JToken.Parse(text); | ||
}); | ||
|
||
Declarative parsers can be defined to map HttpContent to strongly typed objects | ||
|
||
parserStore.AddMediaTypeParser<JToken>("application/json", async (content) => | ||
{ | ||
var stream = await content.ReadAsStreamAsync(); | ||
return JToken.Load(new JsonTextReader(new StreamReader(stream))); | ||
}); | ||
|
||
// Define method to translate media type DOM into application domain object instance based on profile | ||
parserStore.AddProfileParser<JToken, Person>(new Uri("http://example.org/person"), (jt) => | ||
{ | ||
var person = new Person(); | ||
var jobject = (JObject)jt; | ||
person.FirstName = (string)jobject["FirstName"]; | ||
person.LastName = (string)jobject["LastName"]; | ||
|
||
return person; | ||
}); | ||
|
||
var machine = new HttpResponseMachine(parserStore); | ||
|
||
// Define action in HttpResponseMachine for all responses that return 200 OK and can be translated somehow to a Person | ||
machine | ||
.When(HttpStatusCode.OK) | ||
.Then<Person>((m, l, p) => { testPerson = p; }); | ||
|
||
|
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,39 @@ | ||
using System.Net.Http; | ||
using System.Threading.Tasks; | ||
using Tavis.Http; | ||
|
||
namespace Tavis.HttpResponseMachine | ||
{ | ||
/// <summary> | ||
/// HttpResponseHandler that can be chained into a response pipeline | ||
/// </summary> | ||
public abstract class DelegatingResponseHandler : IResponseHandler | ||
{ | ||
public DelegatingResponseHandler InnerResponseHandler { get; set; } | ||
|
||
protected DelegatingResponseHandler() | ||
{ | ||
|
||
} | ||
|
||
protected DelegatingResponseHandler(DelegatingResponseHandler innerResponseHandler) | ||
{ | ||
InnerResponseHandler = innerResponseHandler; | ||
} | ||
|
||
public virtual Task<HttpResponseMessage> HandleResponseAsync(IRequestFactory requestFactory, HttpResponseMessage responseMessage) | ||
{ | ||
if (InnerResponseHandler != null) | ||
{ | ||
return InnerResponseHandler.HandleResponseAsync(requestFactory, responseMessage); | ||
} | ||
|
||
var tcs = new TaskCompletionSource<HttpResponseMessage>(); | ||
tcs.SetResult(responseMessage); | ||
return tcs.Task; | ||
} | ||
} | ||
|
||
|
||
|
||
} |
Oops, something went wrong.