Skip to content

Commit

Permalink
Build status, nuget and usage description
Browse files Browse the repository at this point in the history
[skip ci]
  • Loading branch information
Blind-Striker committed Mar 30, 2018
1 parent ac8e64d commit 7cfb735
Showing 1 changed file with 95 additions and 2 deletions.
97 changes: 95 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,97 @@
# Nancy.Serialization.Hyperion
[![Build Status](https://travis-ci.org/armutcom/Nancy.Serialization.Hyperion.svg?branch=master)](https://travis-ci.org/armutcom/Nancy.Serialization.Hyperion)
Implementations of the ISerialization and IBodyDeserializer interfaces, based on [Hyperion](https://github.com/akkadotnet/Hyperion), for [Nancy](http://nancyfx.org)

Hyperion serializer for Nancy
## Builds status
| | Linux | OS X |
|-------|-------|----------|
| Build | [![Build Status](https://travis-ci-job-status.herokuapp.com/badge/armutcom/Nancy.Serialization.Hyperion/master/linux)](https://travis-ci.org/armutcom/Nancy.Serialization.Hyperion) | [![Build Status](https://travis-ci-job-status.herokuapp.com/badge/armutcom/Nancy.Serialization.Hyperion/master/osx)](https://travis-ci.org/armutcom/Nancy.Serialization.Hyperion) |
## Nuget
| | Stable | Prerelease |
|-------|-------|----------|
| Package | [![Build Status](https://img.shields.io/nuget/v/Nancy.Serialization.Hyperion.svg)](https://www.nuget.org/packages/Nancy.Serialization.Hyperion/) | [![Build Status](https://img.shields.io/nuget/vpre/Nancy.Serialization.Hyperion.svg)](https://www.nuget.org/packages/Nancy.Serialization.Hyperion/) |

## Usage

Start of by installing the `Nancy.Serialization.Hyperion` nuget

When Nancy detects that the `HyperionSerializer` and `HyperionBodyDeserializer` types are available in the AppDomain, of your application, it will assume you want to use them for `application/x-hyperion` content types.

```csharp
public class HomeModule : NancyModule
{
public HomeModule()
{
Get["/user"] = x =>
{
var user = new User()
{
Id = Guid.NewGuid(),
Name = "Ozgen",
Age = 31,
CreateDate = DateTime.Now
};

return Response.AsHyperion<User>(user);
};

Post["PostUser", "/user"] = (o) =>
{
User user = this.Bind<User>();

return "OK";
};
}
}
```

### Client request sample

Start of by installing the `Hyperion` nuget

```csharp
static void Main(string[] args)
{
var serializer = new Serializer(new SerializerOptions(
preserveObjectReferences: true,
versionTolerance: true,
ignoreISerializable: true));

var user = new User()
{
Id = Guid.NewGuid(),
Name = "Deniz",
Age = 31,
CreateDate = DateTime.Now
};

using (var client = new HttpClient())
{
var uri = new Uri("");

using (var stream = new MemoryStream())
{
serializer.Serialize(user, stream);

byte[] content = stream.ToArray();
ByteArrayContent byteArrayContent = new ByteArrayContent(content);
byteArrayContent.Headers.ContentType = new MediaTypeHeaderValue("application/x-hyperion");

Task<HttpResponseMessage> postAsync = client.PostAsync(uri, byteArrayContent);

postAsync.Wait();
}

Task<HttpResponseMessage> getAsync = client.GetAsync(uri);

getAsync.Wait();

Task<Stream> responseAsync = getAsync.Result.Content.ReadAsStreamAsync();
Stream contentStream = responseAsync.Result;

user = serializer.Deserialize<User>(contentStream);
}
}
```

## License
Licensed under Apache 2.0, see [LICENSE](LICENSE) for the full text.

0 comments on commit 7cfb735

Please sign in to comment.