create ServerAPI and optimize the code