Return JSON-responses from the API

Fixes #11.

Relies on #34.

Don't merge yet, need to update the tests.