Add apiPreHandlers and done+fail support on apiHandlers

Change-Id: Ida51b86c4b8e6a4c923155a18f89f4c808c98fcc