sp-rest-proxy - SharePoint REST API Proxy for local Front-end development tool-chains
Allows performing API calls to local Express application with forwarding the queries to a remote SharePoint instance.
Original concept of the proxy was created to show how it could be easy to implements real world data communications for SharePoint Framework local serve mode during web parts debug without deployment to SharePoint tenant. Now the tool is used with multiple teams for modern front-end solutions rapid development.
Supports SPFx and PnP JS Core
Supported SharePoint versions
- SharePoint Online
- SharePoint On-Prem (2019/2016/2013/2010)
- SPA development (Angular, React, Vue.js, etc.) in serve mode against real data for On-Prem and Online
- SharePoint Framework with local workbench
- SharePoint AddIns development
- REST API
- CSOM requests
- SOAP web services
- Static resources
- API Proxy server
- Socket gateway server
- Socket gateway client
Socket proxying allows to forward API from behind NAT (experimental).
How to use as a module
1. Install NPM module in the project:
npm install sp-rest-proxy --save-dev
2. Create server.js with the following code:
const RestProxy = ;const settings =configPath: './config/private.json' // Location for SharePoint instance mapping and credentialsport: 8080 // Local server portstaticRoot: './static' // Root folder for static content;const restProxy = settings;restProxy;
3. Add npm task for serve into package.json:
Check if the path to server.js is correct.
npm run serve.
5. Provide SharePoint configuration parameters.
6. Test local API proxy in action.
How to develop
1. Clone/fork the project:
git clone https://github.com/koltyakov/sp-rest-proxy
2. CMD to the project folder.
3. Install dependencies:
npm run build
5. Run the server:
npm run serve
or serve in TypeScript directly
npm run ts-serve
Prompts credentials for a SharePoint site.
6. Navigate to
http://localhost:8080 (or whatever in settings)
7. Ajax REST calls as if you were in SharePoint site page context:
npm run test
In early days of
sp-rest-proxy, the library was written in ES6 and used
module.exports which was kept after migrating to TypeScript later on for the backward compatibility reasons.
In TypeScript, it's better to import the lib from
sp-rest-proxy/dist/RestProxy to get advantages of types:
The proxy provides wizard-like approach for building and managing config files for
node-sp-auth (Node.js to SharePoint unattended http authentication).
- SharePoint 2013, 2016:
- Addin only permissions
- User credentials through the http ntlm handshake
- Form-based authentication (FBA)
- SharePoint Online:
- Addin only permissions
- SAML based with user credentials
- ADFS user credentials (works with both SharePoint on-premise and Online)
sp-rest-proxy works with PnPjs (check out brief notice how to configure).
Load page context helper
sp-rest-proxy includes helper method for configuring page context -
;;// loadPageContext - gets correct URL in localhost and SP environmentsloadPageContext.then.catchlog;
JSOM can be used in local development mode with sp-rest-proxy with some additional setup.
The local development workbench page should contain JSOM init scripts:
Check out the example.
- Client side applications development with local serve, but real data from SharePoint
- SharePoint Framework in local workbench with real data
- Client applications integration test automation scenarios