1
votes

Presently I am using the following method to get the server relative URL

function getLibraryUrl(nameOrUrl)
    {
        var ctx = SP.ClientContext.get_current();
        var list = ctx.get_web().get_lists().getByTitle(nameOrUrl);
        ctx.load(list,'RootFolder');
        ctx.executeQueryAsync(
                            function(){
                            var url=list.get_rootFolder().get_serverRelativeUrl();
                            return url;
                            },
                            function(sender, args)
                                    {

     });    
    }

But, I don't want to use the asynchronous call. Can any one please guide me to get the server relative URL of document library using rest API.

Something like this /_api/Web/Lists/getByTitle('')/items?$select=File/ServerRelativeUrl&$expand=File

1

1 Answers

3
votes

Yes you can get ServerRelativeUrl of document library using REST API.

Refer below REST URL :

https://abcd.sharepoint.com/sites/RohitW/_api/Web/lists/getbytitle('DocLibTest1')/RootFolder

Output :

enter image description here