Spike for a new API for declaring endpoints

Yup, that will reduce the code duplication. I will do it in a couple of minutes.