Add ability to wrap response in an envelope

Updates #507 from @Japh for 2.0.

Fixes #370.