Update to use REST API

Quite a big rewrite.