From 7cfb73597515d6d1445d023ff1199df9c098928c Mon Sep 17 00:00:00 2001 From: "deniz@armut.com" Date: Fri, 30 Mar 2018 14:05:12 +0300 Subject: [PATCH] Build status, nuget and usage description [skip ci] --- README.md | 97 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 95 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d423a41..f3e02d6 100644 --- a/README.md +++ b/README.md @@ -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); + }; + + Post["PostUser", "/user"] = (o) => + { + User user = this.Bind(); + + 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 postAsync = client.PostAsync(uri, byteArrayContent); + + postAsync.Wait(); + } + + Task getAsync = client.GetAsync(uri); + + getAsync.Wait(); + + Task responseAsync = getAsync.Result.Content.ReadAsStreamAsync(); + Stream contentStream = responseAsync.Result; + + user = serializer.Deserialize(contentStream); + } +} +``` + +## License +Licensed under Apache 2.0, see [LICENSE](LICENSE) for the full text.