Refactor: Add middleware for sending data

On the server side, sending data straight
from the data-access object to the client
can be done in a general way.

It only cuts down code duplication in two
places, but this is a stepping stone to
larger refactorings.