Over the last couple of days I’ve been playing around with Nancy, one of a number of micro web frameworks now available for the .Net platform. You can read more about Nancy on their github readme page but in short it’s an ultra lightweight, easily extensible framework that lets you run a HTTP web server in a number of hosting environments (IIS, WCF, or inside a simple console app) and can integrate with a number of view engines (Razor, Spark, NDjango, etc).
If you’re not familiar with how Nancy works, I’d recommend taking half an hour or so and go through the documentations first.
On the deserialization side, Nancy supports JSON and XML binding out of the box, to add protocol buffer support to the equation all you need to do is to create a class that implements the IBodyDeserializer interface and the Nancy bootstrapper will take care of the rest (it auto registers all the implementations of the relevant interfaces at startup).
However, if there are more than one implementation of IBodyDeserialize defined in the loaded assembly which can deserialize the content type application/x-protobuf then at runtime the deserializer will be chosen at random.
To serialize the response body with protobuf-net, all you need to do in the handler is to return a Response object and serialize the object you want to return like this:
Alternatively, you can create a subtype of Response and take in the object you want to use as the response body and automatically serialize it, something along the line of:
I’m an AWS Serverless Hero and the author of Production-Ready Serverless. I have run production workload at scale in AWS for nearly 10 years and I have been an architect or principal engineer with a variety of industries ranging from banking, e-commerce, sports streaming to mobile gaming. I currently work as an independent consultant focused on AWS and serverless.
Here is a complete list of all my posts on serverless and AWS Lambda. In the meantime, here are a few of my most popular blog posts.
- Lambda optimization tip – enable HTTP keep-alive
- You are thinking about serverless costs all wrong
- Many faced threats to Serverless security
- We can do better than percentile latencies
- I’m afraid you’re thinking about AWS Lambda cold starts all wrong
- Yubl’s road to Serverless
- AWS Lambda – should you have few monolithic functions or many single-purposed functions?
- AWS Lambda – compare coldstart time with different languages, memory and code sizes
- Guys, we’re doing pagination wrong