spfx-rest-rvt
v6.0.0
Published
A TypeScript library for interacting with SharePoint REST APIs in SPFx projects
Maintainers
Readme
SharepointService - spfx-rest-rvt
A utility wrapper around SharePoint REST API for SPFx solutions using SPHttpClient.
Package:
spfx-rest-rvt
Import Path:spfx-rest-rvt/dist
Features
- Simplifies SharePoint REST API usage in SPFx
- Supports item CRUD, file/folder operations, permissions, navigation, user profile, etc.
- Handles large list pagination
- CAML query support
- Site and list provisioning utilities
📦 Installation
npm install spfx-rest-rvt🚀 Usage
import { SharepointService } from "spfx-rest-rvt/dist";
import { WebPartContext } from "@microsoft/sp-webpart-base";
const spService = new SharepointService(context); // context is of type WebPartContext
// Get items from a list
spService.getListItems("Documents")
.then(response => response.json())
.then(data => {
console.log("Items:", data.value);
});
🔧 Constructor
new SharepointService(context: WebPartContext, siteUrl?: string);context: SPFx WebPart contextsiteUrl(optional): To target a different site than the current one
📘 API Overview
📄 List Item Methods
| Method | Description |
|--------|-------------|
| getListItems(listName, filter?) | Get items by list name |
| getListItemsByListId(listId, filter?) | Get items by list ID |
| getListItemsByListIdRecursive(listId, filter?) | Get all items (recursive) by list ID |
| getListItemsByListTitleRecursive(listTitle, filter?) | Get all items (recursive) by list title |
| getListItemsByListIdWithPagination(listId, top, skip) | Paginated items |
| getListItemsByCamlQuery(listName, camlQuery) | Items using CAML |
| getListItemById(listName, itemId, filter?) | Single item |
| createOrUpdateListItem(listName, body, itemID?) | Create or update item |
| UpdateListItem(listId, body, itemID) | Update item by list ID |
| deleteListItem(listName, itemId) | Delete item |
📁 File & Folder Operations
| Method | Description |
|--------|-------------|
| uploadFile(folderPath, fileName, fileContent) | Upload file |
| getAllFilesInFolder(folderUrl) | Get files in folder |
| getFiles(libraryUrl) | Recursively get all files |
| getFolders(libraryUrl) | Recursively get all folders |
| getAllFoldersRecursively(libraryName) | Get all nested folders |
| getFilesAndFolders(libraryUrl) | Get files + folders |
| createFolder(libraryName, folderName) | Create folder |
| updateFileMetadata(fileUrl, metadata) | Update metadata |
| deleteFile(fileUrl) | Delete file |
📎 Attachment Operations
| Method | Description |
|--------|-------------|
| addAttachmentToListItem(listName, itemId, fileName, fileContent) | Add attachment |
| deleteAttachmentFromListItem(listName, itemId, fileName) | Delete attachment |
🧾 List Metadata
| Method | Description |
|--------|-------------|
| getListColumns(listName, filter?) | Columns by name |
| getListColumnsByListId(listId, filter?) | Columns by ID |
| getDefaultViewFields(listId) | View fields |
| getListViews(listName) | All views of list |
🏗 List and Site Management
| Method | Description |
|--------|-------------|
| getList(listName) | Get list info |
| getLists() | All lists/libraries |
| createList(listName, description) | Create list |
| updateList(listName, body) | Update list |
| deleteList(listName) | Delete list |
| createSubsite(title, url, description, template) | Create subsite |
| deleteSubsite(subsiteUrl) | Delete subsite |
| getSiteCollection() | Get site collection details |
👥 User & Group Management
| Method | Description |
|--------|-------------|
| getUserDetails(email) | Get user by email |
| getUserProfile() | Current user's profile |
| getCurrentUser() | Current user object |
| getSiteUsers() | All users in site |
| getSiteGroups() | All site groups |
| addUserToGroup(groupId, userLoginName) | Add user to group |
| removeUserFromGroup(groupId, userId) | Remove user from group |
🔐 Permissions
| Method | Description |
|--------|-------------|
| getSitePermissions() | Role assignments & bindings |
| addUserOrGroupToSitePermissions(principalId, roleDefId) | Add user/group to role |
| removeUserOrGroupFromSitePermissions(principalId, roleDefId) | Remove user/group from role |
📚 Versioning
| Method | Description |
|--------|-------------|
| getVersionHistory(listId, itemId) | Get item versions |
| restoreVersion(listId, itemId, versionId, fileName?) | Restore list item version |
| restoreFileVersion(serverRelativeUrl, versionLabel) | Restore file version |
📂 Navigation
| Method | Description |
|--------|-------------|
| getSiteNavigation() | Quick launch navigation |
✅ Example
const spService = new SharepointService(context);
// Get items from a list
spService.getListItems("Documents")
.then(response => response.json())
.then(data => {
console.log("Items:", data.value);
});
// Upload file
const blob = new Blob(["Hello SharePoint!"], { type: "text/plain" });
spService.uploadFile("Shared Documents", "hello.txt", blob)
.then(response => response.json())
.then(data => {
console.log("Uploaded:", data);
});📄 License
MIT
🙋♂️ Support
For bugs, issues, or contributions, please raise a GitHub issue or pull request.
