extracting common API handler behavior