Add eventsource API

Refactor the protocol into its own module