Say my filepath is http://server/subsite/library/folder/file.png. If I need to get information about a file, I need to do the following:
http://server/subsite/_api/web/GetFileByServerRelativeUrl('/subsite/library/folder/file.png').
Now the problem is I don't know which sections are the subsite(s), so I have to run the follow _vti_bin/webs.asmx/WebUrlFromPageUrl which will get me the web url. So for the above filepath it will return http://server/subsite and now I have the required context for the REST _api.
Is there an easier way of doing this? I'm relying on the REST api and the I know the asmx handlers are very old and deprecated. I don't mind doing two requests to get the information I want but is there a REST equivalent of _vti_bin/webs.asmx/WebUrlFromPageUrl?
Edit: I am calling the sharepoint rest api from an external service. It is not a sharepoint app.
webServerRelativeUrl/webAbsoluteUrl/siteAbsoluteUrl/siteServerRelativeUrlfrom_spPageContextInfoin JavaScript of a client browser or something, I also made a HTTP request (WebUrlFromPageUrl). If worrying about asmx handlers are very old and deprecated, maybe use new OData API (i.e. https://{{SPWebServer}}/_api/sp.web.getweburlfrompageurl(@v)?@v='xx') withX-RequestDigestheader. See also sharepoint.stackexchange.com/questions/224893/…{{SPWebServer}}may look like{{tenant}}.sharepoint.comorsharepoint.company0.comand it doesn't needsiteServerRelativeUrl. And the API returnswebAbsoluteUrl/siteAbsoluteUrl, e.g.{"value":"https://company0test2.sharepoint.com/tit"}for@v='https://company0test2.sharepoint.com/:x:/g/tit/EeFmOJxxxxxxxxxxxxxxxxxxxxxxx-eb0xxxxxxxxxxl1g?e=9kXxdl'