I love that you are using the XmlSerializer by default, rather than the Data Contract Serializer. It is great to have full control of the format of the data being exposed. Two suggestions for additional formatters:
HTML - a formatter than handled requests for media types such as application/xhtml+xml, text/html and */* which return HTML would allow for a read only version of the service in which data and
help text can be embedded. This would use the existing ASPX / CSHTML rendering engines available in ASP.Net MVC... i.e. delegate to the normal request processing.
JSON.Net - less likely I guess, but James Newton-King's JSON serializer provides much the same formatting power as the XmlSerializer, supportting many equivalent attributes (e.g. JsonIgnore
to mirror XmlIgnore). This means model classes can be created to reflect internal needs but be serialised in a format most acceptable to clients. I guess support for this could come from the community, but it would be fantastic to bring it into the fold.
MS said in a live meeting on ASP.NET Web API that they plan to have JSON.Net support out of the box. There's also an example blog post that shows how to hook it up yourself:
http://blogs.msdn.com/b/henrikn/archive/2012/02/18/using-json-net-with-asp-net-web-api.aspx
For my Resources Over MVC framework I created an XHTML Formatter that used the standard Razor engine as wrapped up by ASP.Net MVC and this
blog post shows how this give a very useful additional representation (or two if you include help). The feedback I had regarding providing inline help and a browsable API was very positive. This would require a little more than a simple hosting of the Razor
engine as it benefitted from MVCs ability to discover which View to use.
I will make a ProtoBuf.Net formatter at some point. This is a definite must-have. ProtoBuf is incredibly fast over the wire and serializes and deserializes much quicker than json or xml
I will make a ProtoBuf.Net formatter at some point. This is a definite must-have. ProtoBuf is incredibly fast over the wire and serializes and deserializes much quicker than json or xml
I'd love to see that :) I quite like Protobuf, just don't have a case where I need to use it atm.. Everyone at my workplace is agreeing on JSON as the cross-platform format of choice.
pierslawson
Member
48 Points
35 Posts
Suggestions for MediaTypeFormatters / Serializers
Feb 20, 2012 10:06 AM|LINK
I love that you are using the XmlSerializer by default, rather than the Data Contract Serializer. It is great to have full control of the format of the data being exposed. Two suggestions for additional formatters:
HTML - a formatter than handled requests for media types such as application/xhtml+xml, text/html and */* which return HTML would allow for a read only version of the service in which data and help text can be embedded. This would use the existing ASPX / CSHTML rendering engines available in ASP.Net MVC... i.e. delegate to the normal request processing.
JSON.Net - less likely I guess, but James Newton-King's JSON serializer provides much the same formatting power as the XmlSerializer, supportting many equivalent attributes (e.g. JsonIgnore to mirror XmlIgnore). This means model classes can be created to reflect internal needs but be serialised in a format most acceptable to clients. I guess support for this could come from the community, but it would be fantastic to bring it into the fold.
SiggiGG
Member
265 Points
105 Posts
Re: Suggestions for MediaTypeFormatters / Serializers
Feb 20, 2012 10:55 AM|LINK
MS said in a live meeting on ASP.NET Web API that they plan to have JSON.Net support out of the box. There's also an example blog post that shows how to hook it up yourself:
http://blogs.msdn.com/b/henrikn/archive/2012/02/18/using-json-net-with-asp-net-web-api.aspx
pierslawson
Member
48 Points
35 Posts
Re: Suggestions for MediaTypeFormatters / Serializers
Feb 20, 2012 10:58 AM|LINK
Cool, one down, one to go
pierslawson
Member
48 Points
35 Posts
Re: Suggestions for MediaTypeFormatters / Serializers
Feb 27, 2012 01:01 PM|LINK
For my Resources Over MVC framework I created an XHTML Formatter that used the standard Razor engine as wrapped up by ASP.Net MVC and this blog post shows how this give a very useful additional representation (or two if you include help). The feedback I had regarding providing inline help and a browsable API was very positive. This would require a little more than a simple hosting of the Razor engine as it benefitted from MVCs ability to discover which View to use.
aemami99
Member
17 Points
13 Posts
Re: Suggestions for MediaTypeFormatters / Serializers
Feb 27, 2012 03:00 PM|LINK
I will make a ProtoBuf.Net formatter at some point. This is a definite must-have. ProtoBuf is incredibly fast over the wire and serializes and deserializes much quicker than json or xml
SiggiGG
Member
265 Points
105 Posts
Re: Suggestions for MediaTypeFormatters / Serializers
Feb 27, 2012 03:02 PM|LINK
I'd love to see that :) I quite like Protobuf, just don't have a case where I need to use it atm.. Everyone at my workplace is agreeing on JSON as the cross-platform format of choice.