Refactor prepare routes method

This PR refactors the prepare_routes method in Endpoint, extracting two methods to make it more readable.
This is strange, does `fetch` need a block here? Can we rewrite it not to need that?