Rebased #1787 - Initial REST API

For discussion see #1787.