MDL-39152 webservices: Abstract context fetching

Since many apis in future will need to provide alternative method to fetch context, I have abstracted this bit into the core external_api class