All Projects → koltyakov → Sp Rest Proxy

koltyakov / Sp Rest Proxy

Licence: mit
🌐 SharePoint REST API Proxy for local Front-end development tool-chains

Programming Languages

javascript
184084 projects - #8 most used programming language
typescript
32286 projects

Projects that are alternatives of or similar to Sp Rest Proxy

Flaresolverr
Proxy server to bypass Cloudflare protection
Stars: ✭ 241 (+63.95%)
Mutual labels:  api, rest, proxy
Httpie
As easy as /aitch-tee-tee-pie/ 🥧 Modern, user-friendly command-line HTTP client for the API era. JSON support, colors, sessions, downloads, plugins & more. https://twitter.com/httpie
Stars: ✭ 53,052 (+35989.8%)
Mutual labels:  api, rest, developer-tools
Service Proxy
API gateway for REST and SOAP written in Java.
Stars: ✭ 355 (+141.5%)
Mutual labels:  api, rest, proxy
Grafanajsondatasource
Grafana datasource to load JSON data over your arbitrary HTTP backend
Stars: ✭ 146 (-0.68%)
Mutual labels:  api, rest
Core
OPNsense GUI, API and systems backend
Stars: ✭ 1,827 (+1142.86%)
Mutual labels:  api, proxy
Api Guidelines
adidas group API design guidelines
Stars: ✭ 147 (+0%)
Mutual labels:  api, rest
Gandi Live Dns
DynDNS Updater for Gandi LiveDNS REST API
Stars: ✭ 116 (-21.09%)
Mutual labels:  api, rest
Aping
angular module to get and display data by adding html-attributes
Stars: ✭ 135 (-8.16%)
Mutual labels:  api, rest
Zoomhub
Share and view high-resolution images effortlessly
Stars: ✭ 122 (-17.01%)
Mutual labels:  api, rest
Open Rest
Standard rest server, Base on restify and sequelize
Stars: ✭ 136 (-7.48%)
Mutual labels:  api, rest
Strapi Plugin Comments
A plugin for Strapi Headless CMS that provides end to end comments feature with their moderation panel, bad words filtering, abuse reporting and more.
Stars: ✭ 138 (-6.12%)
Mutual labels:  api, rest
Esp V2
A service proxy that provides API management capabilities using Google Service Infrastructure.
Stars: ✭ 120 (-18.37%)
Mutual labels:  api, proxy
Narration
The Narration PHP Framework - Empowering everyone to build reliable and loosely coupled web apps.
Stars: ✭ 119 (-19.05%)
Mutual labels:  api, rest
Node Express Mongoose Passport Jwt Rest Api Auth
Node, express, mongoose, passport and JWT REST API authentication example
Stars: ✭ 146 (-0.68%)
Mutual labels:  api, rest
Rest Api Fuzz Testing
REST API Fuzz Testing (RAFT): Source code for self-hosted service developed for Azure, including the API, orchestration engine, and default set of security tools (including MSR's RESTler), that enables developers to embed security tooling into their CI/CD workflows
Stars: ✭ 119 (-19.05%)
Mutual labels:  api, rest
Subzero Starter Kit
Starter Kit and tooling for authoring GraphQL/REST API backends with subZero
Stars: ✭ 136 (-7.48%)
Mutual labels:  api, rest
Poloniex Api Node
Poloniex API client for REST and WebSocket API
Stars: ✭ 138 (-6.12%)
Mutual labels:  api, rest
Postman Bdd
A BDD test framework for Postman and Newman
Stars: ✭ 139 (-5.44%)
Mutual labels:  api, rest
Htty
htty is the HTTP TTY, a console application for interacting with web servers.
Stars: ✭ 1,755 (+1093.88%)
Mutual labels:  rest, developer-tools
Json Serverless
Transform a JSON file into a serverless REST API in AWS cloud
Stars: ✭ 108 (-26.53%)
Mutual labels:  api, rest

sp-rest-proxy - SharePoint REST API Proxy for local Front-end development tool-chains

NPM

npm version Downloads Build Status FOSSA Status Gitter chat

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.

In a nutshell

Supports SPFx and PnP JS

Supported SharePoint versions

  • SharePoint Online
  • SharePoint On-Prem (2019, 2016, 2013)
  • SharePoint On-Prem 2010 (limited support)

Development paradigms

Supports proxying

  • REST API
  • CSOM requests
  • SOAP web services
  • Custom services
  • Static resources

Proxy modes

  • API Proxy server
  • Socket gateway server
  • Socket gateway client
  • Custom Express apps embed mode

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

2. Create server.js with the following code:

const RestProxy = require('sp-rest-proxy');

const settings = {
  configPath: './config/private.json', // Location for SharePoint instance mapping and credentials
  port: 8080,                          // Local server port
  staticRoot: './static'               // Root folder for static content
};

const restProxy = new RestProxy(settings);
restProxy.serve();

Configuration parameters cheatsheet

3. Add npm task for serve into package.json:

"scripts": {
  "serve": "node ./server.js"
}

Check if the path to server.js is correct.

4. Run npm run serve.

5. Provide SharePoint configuration parameters.

6. Test local API proxy in action.

How to develop

Install

1. Clone/fork the project:

git clone https://github.com/koltyakov/sp-rest-proxy

2. CMD to the project folder.

3. Install dependencies:

npm install

4. Build:

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:

REST Client Example

8. Tests.

npm run test

Tests Example

Webpack Dev Server

/* webpack.config.js */
const RestProxy = require('sp-rest-proxy');

const port = process.env.WEBPACK_DEV_SERVER_PORT || 9090;

module.exports = {
  // Common Webpack settings
  // ...
  devServer: {
    watchContentBase: true,
    writeToDisk: true,
    port,
    before: (app) => {
      // Register SP API Proxy
      new RestProxy({ port }, app).serveProxy();

      // Other routes
      // ...
    }
  }
};

TypeScript support

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:

import RestProxy, { IProxySettings } from 'sp-rest-proxy/dist/RestProxy';

const settings: IProxySettings = {
  configPath: './config/private.json'
};

const restProxy = new RestProxy(settings);
restProxy.serve();

Authentication settings

The proxy provides wizard-like approach for building and managing config files for node-sp-auth (Node.js to SharePoint unattended http authentication).

  • SharePoint Online:
    • User credentials (SAML/ADFS)
    • Add-In Only permissions
    • On-Demand authentication (using Electron popup)
  • SharePoint 2019, 2016, 2013:
    • User credentials (NTLM, NTLM v2)
    • ADFS user credentials
    • Form-based authentication (FBA)
    • Form-based authentication (Forefront TMG)
    • Add-In Only permissions
    • On-Demand authentication (using Electron popup)
  • SharePoint 2010:
    • User credentials (NTLM, NTMLv2)
    • Form-based authentication (FBA)
    • Form-based authentication (Forefront TMG)

For more information please check node-sp-auth credential options and wiki pages. Auth settings are stored inside ./config/private.json.

PnPjs

sp-rest-proxy works with PnPjs (check out brief notice how to configure).

PnP JS + sp-rest-proxy

Load page context helper

sp-rest-proxy includes helper method for configuring page context - loadPageContext.

import { loadPageContext } from 'sp-rest-proxy/dist/utils/env';
import { Web } from '@pnp/sp';

// loadPageContext - gets correct URL in localhost and SP environments
loadPageContext().then(async () => {

  // In both localhost and published to SharePoint page
  // `_spPageContextInfo` will contain correct info for vital props

  // PnPjs's Web object should be created in the following way
  const web = new Web(_spPageContextInfo.webAbsoluteUrl);

  // Then goes ordinary PnPjs code
  const batch = web.createBatch();

  const list = web.getList(`${_spPageContextInfo.webServerRelativeUrl}/List/ListName`);
  const entityName = await list.getListItemEntityTypeFullName();

  [1, 2, 3, 4].forEach((el) => {
    list.items.inBatch(batch).add({
      Title: `${el}`
    }, entityName);
  });

  await batch.execute();
  console.log('Done');

}).catch(console.warn);

JSOM (SharePoint JavaScript Object Model)

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:

<script type="text/javascript" src="/_layouts/15/1033/initstrings.js"></script>
<script type="text/javascript" src="/_layouts/15/init.js"></script>
<script type="text/javascript" src="/_layouts/15/MicrosoftAjax.js"></script>
<script type="text/javascript" src="/_layouts/15/sp.core.js"></script>
<script type="text/javascript" src="/_layouts/15/sp.runtime.js"></script>
<script type="text/javascript" src="/_layouts/15/sp.js"></script>

Check out the example.

SharePoint Framework

Blog post article with setting up SPFx and Proxy

Use cases

  • 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

Usage with Docker

License

FOSSA Status

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].