rest middleware