See ``xwiki.js`` for ``XWiki.Document#getRestURL()``. No need to duplicate the code.