beginning of API handler