api: support TLS

Related to #178. Would probably close it, but I need to make some manual
tests in the client.