[api] Consolidate http reply code into single function