View on GitHub

SharePoint REST Framework

NuGet Current Version Downloads Total Downloads Gitter chat Donate

Overview:

The SharePoint REST Framework was designed for SharePoint 2013, but works in both SharePoint 2013/2016 and Office 365. This framework is designed to remove the overhead of SharePoint development, allowing the developer to focus on the client requirements. A reference to the associated github projects are listed below:

gd-sprest vs pnp-js-core

The gd-sprest library is similar to the pnp-js-core, with the main difference being the ability to be used within the browser console window. This feature provides a “Powershell-Like” experience within the browser console window. Some reasons to use this functionality:

Bugs/Feature Requests/Help

Click Here to report any bugs, request any new features or if need help with code examples. Pull requests are welcomed for anyone interested in submitting them. Feel free to email for other questions.

Security

The REST api execute requests based on the user’s permissions. There is no way to elevate priviledges requests against the SharePoint REST.

Get Started

Packages

NPM

Add the npm package to your project:

npm --save install gd-sprest

Yarn

Add the package from yarn:

yarn add gd-sprest

Code Examples

JavaScript

var $REST = require("gd-sprest");

// Get the current web and lists
$REST.Web().query({
    Expand: ["Lists"]
}).execute(function(web) {
    // Parse the lists
    for(var i=0; i<web.Lists.results.length; i++) {
        var list = web.Lists.results[i];
    }
});

NodeJS

const $REST = require("gd-sprest);

// Create a new generic list.
request = $REST.Web("https://dev.sharepoint.com")
    .Lists().add({
        BaseTemplate: $REST.SPTypes.ListTemplateType.GenericList,
        Title: "New List"
    });

// Log the request information
console.log(request.getInfo());

// Console Output:
// {
//     data: '{"BaseTemplate":100,"Title":"New List","__metadata":{"type":"SP.List"}}',
//     method: 'POST',
//     url: 'https://dev.sharepoint.com'
// }

TypeScript

import { List }

// Get the "Site Assets" library, fields and views
(new List("Site Assets"))
    // Query the list
    .query({
        Expand: ["Fields", "Views"]
    })
    // Execute the request
    .execute((list) => {
        // Parse the fields
        for(let i=0; i<list.Fields.results.length; i++) {
            let field = list.Fields.results[i];
        }

        // Parse the views
        for(let i=0; i<list.Views.results.length; i++) {
            let field = list.Views.results[i];
        }
    });

Development

Add-In Model

The add-in model uses the app web for SharePoint Hosted Apps/Add-Ins. The provider hosted model would use CSOM, and not this library. This framework has built-in helper methods and a global flag for determining which web the request should execute against Host vs App/Add-In. The request will be automatically updated based on the target web, so there is no additional code required from the developer. This allows the developer to create a single source of code that works against both the SharePoint and App/Add-In webs.

Available Libraries

import {
    $REST,
    ContextInfo,
    Email,
    Helper,
    JSLink,
    List,
    PeopleManager,
    PeoplePicker,
    ProfileLoader,
    RequestType,
    Search,
    Site,
    SocialFeed,
    SPTypes,
    Types,
    UserProfile,
    Web
} from "gd-sprest";

Automation

The “SharePoint Configuration” class allows the developer to define configuration files for the SharePoint solution. This class contains built-in methods for execution (install, uninstall, etc), so there is no need to write additional code.

Intellisense

One of the more important features of this framework is the intellisense. The classes have been setup to ensure the developer does not need to define the output type of the request. The “Types” and “SPTypes” classes can both be imported into the project. The “Types” class includes allows of the interfaces available in the library. The “SPTypes” class contains all of the enumerators in SharePoint. These interfaces can be used to provide intellisense for the custom variables.

Modern Experience in SharePoint 2013

The gd-sprest-react library contains SharePoint components:

WebParts

The webpart component allows the developer to easialy assign react components to be rendered based on the page’s state (Display/Edit). This component currently supports webpart, publishing and wiki pages. The following webpart components are available:

Various Project Examples

The gd-sprest-webparts github project contains the latest code samples.