Refactor api.py
Refactor api.py

All responses to the client sent by single method `_write_response`
encode('utf-8') is done only inside this method. It make easier to
support existing code because eliminates need to put b'' everywhere

zalando/patroni,zalando/patroni