Provides a clean, concise API that greatly simplifies asynchronous REST interaction with SharePoint. Easily read/write List items (CRUD), execute REST calls, and gather site/user/group information. Enables rapid development of SharePoint Apps/Add-ins using the JavaScript SharePoint App Model.
- Simple - Most REST/Web Service interaction can be done in a few lines of code
- Modern - Lightweight, pure JavaScript solution with no dependencies
- Elegant - Utilizes the new ES6 Promise architecture for asynchronous operations
- Robust - Built for SharePoint 2013 API and OData v3
- List Methods - Create, read, update, and delete (CRUD) List/Library items with a single line of code
- User Methods - Get User information: Basic (ID, Email, LoginName, etc.) and UserProfile (Manager, 100+ Properties)
- Site Methods - Get Site information (Lists, Groups, Users, Roles, Subsites and Permissions)
- REST Methods - Call any available SharePoint REST API endpoint
- Form Population - Populate form elements using data-bind declarative binding system like Knockout or AngluarJS
- SharePoint 2013 (SP2013), SharePoint 2016 (SP2016), SharePoint Online (Office 365)
sprLib.rest(options)
- Returns the results of a given REST call to any SharePoint REST API
sprLib.list(listName).items(options)
- Returns an array of item objects using a variety of possible optionssprLib.list(listName).create(item)
- Create a new list item using JSON datasprLib.list(listName).update(item)
- Update an existing item using JSON datasprLib.list(listName).delete(item)
- Delete an existing item using JSON data (permanently delete)sprLib.list(listName).recycle(item)
- Recycle an existing item using JSON data (move to Recycle Bin)sprLib.list(listName).cols()
- Returns an array of column objects with useful info (name, datatype, etc.)sprLib.list(listName).info()
- Returns information about the List/Library (GUID, numberOfItems, etc.)sprLib.list(listName).perms()
- Returns an array of the list's Member/Roles objects
sprLib.site(siteUrl).groups()
- Returns an array of the site's Groups and MemberssprLib.site(siteUrl).info()
- Returns over a dozen site properties (ID, Owner, Language, Logo, etc.)sprLib.site(siteUrl).lists()
- Returns an array of the site's Lists/LibrariessprLib.site(siteUrl).perms()
- Returns an array of the site's Member/Roles objectssprLib.site(siteUrl).roles()
- Returns an array of the site's RolessprLib.site(siteUrl).subsites()
- Returns an array of the site's SubsitessprLib.site(siteUrl).users()
- Returns an array of the site's Users and their base permissions
sprLib.user(options).groups()
- Returns an object withSP.Group
group properties (Id, Owner, Title, etc.)sprLib.user(options).info()
- Returns an object withSP.User
user properties (Id, Email, Login, Title, etc.)sprLib.user(options).profile()
- ReturnsSP.UserProfile.PersonProperties
(DirectReports, PictureUrl, etc.)
sprLib.renewSecurityToken()
- Refreshes the SharePoint page security digest token
data-sprlib{options}
- Populates the parent tag using the options provided
- Library Test Drive
- Installation
- Method Reference
- Library Features and Notes
- Issues / Suggestions
- Supported SharePoint Versions
- Special Thanks
- License
You should test drive SpRestLib! It's super easy:
Just open your browser's Developer Tools window anywhere on your SharePoint site, then run the following code snippet which will load the SpRestLib bundle script dynamically:
// 1: Load SpRestLib via CDN var script = document.createElement('script'); script.src = "https://cdn.rawgit.com/gitbrent/SpRestLib/v1.5.0/dist/sprestlib.bundle.js"; document.getElementsByTagName('head')[0].appendChild(script); // 2: Test drive some library methods // Show current user info sprLib.user().info().then( objUser => (console.table ? console.table([objUser]) : console.log(objUser)) ); // Show all Lists/Libraries on the current Site sprLib.site().lists().then( arrLists => (console.table ? console.table(arrLists) : console.log(arrLists)) );
<script lang="javascript" src="https://yourhost.com/subsite/SiteAssets/js/sprestlib.js"></script>
- IE11 support requires a Promises polyfill as well (included in the
libs
folder)
<script lang="javascript" src="https://yourhost.com/subsite/SiteAssets/js/sprestlib.bundle.js"></script>
sprestlib.bundle.js
includes all required libraries (SpRestLib + Promises)
<script lang="javascript" src="https://yourhost.com/subsite/SiteAssets/js/sprestlib-ui.bundle.js"></script>
sprestlib-ui.bundle.js
includes all required libraries plus UI (SpRestLib and SpRestLib-UI + jQuery and Promises)
bower install sprestlib
npm install sprestlib var sprLib = require("sprestlib");
- Desktop: Compatible with Electron applications.
SharePoint Authentication Notes
Using SpRestLib with React, Angular, SharePoint Electron, etc. Integration with Other Libraries
- SpRestLib can be utilized via Node.js to perform powerful operations, generate reports, etc.
- See the
example
directory for a complete, working demo of connecting to SharePoint Online.
See SharePoint Authentication Notes for issues with authentication.
Please file issues or suggestions on the issues page on GitHub, or even better, submit a pull request. Feedback is always welcome!
When reporting issues, please include a code snippet or a link demonstrating the problem.
Does SpRestLib support SharePoint 2010 or 2007?
Unfortunately, older versions cannot be supported. The SharePoint 2007/2010 API utilized SOAP web services with XML (_vti_bin/lists.asmx
endpoints) while the current API uses a completely new (_api/web/lists()
endpoint) backed by REST services.
- Marc D Anderson - SpRestLib is built in the spirit of the late, great
SPServices
library - Microsoft - for the SharePoint.com developer account
- Everyone who submitted an Issue or Pull Request
Copyright © 2016-2018 Brent Ely