Optimizing rest api