general code for endpoint