add a general function for rest