January 24th, 2018

Introducing PnPJS client-side libraries for Office 365

The SharePoint Patterns and Practices Team is excited to announce the release of the Patterns and Practices Client-side Libraries (PnPJS).

Introduction

PnPJS is a fluent JavaScript API for consuming SharePoint and Office 365 REST APIs in a type-safe way. You can use it with SharePoint Framework, Nodejs, or JavaScript projects. This an open source initiative complements existing SDKs provided by Microsoft offering developers another way to consume information from SharePoint and Office 365.

PnP Client Libraries

There are nine packages included in the initial release. Each is linked to its specific documentation where you can find more details.

  • @pnp/common – Provides shared functionality across all pnp libraries
  • @pnp/config-store – Provides a way to manage configuration within your application
  • @pnp/graph – Provides a fluent API for working with Microsoft Graph
  • @pnp/logging – Light-weight, subscribable logging framework
  • @pnp/nodejs – Provides functionality enabling the @pnp libraries within nodejs
  • @pnp/odata – Provides shared odata functionality and base classes
  • @pnp/pnpjs – Rollup library of core functionality (mimics sp-pnp-js structure in previous version)
  • @pnp/sp – Provides a fluent API for working with SharePoint REST
  • @pnp/sp-addinhelpers – Provides functionality for working within SharePoint add-ins

Usage

The libraries have interrelated peer dependencies, so you will need to install these as well as the primary package you wish to use. We will take as an example the task of getting a SharePoint web’s title. First, we need to install the @pnp/sp library as well as the libraries upon which it depends.

npm install @pnp/logging @pnp/common @pnp/odata @pnp/sp --save

Next, we will import and use the functionality from @pnp/sp within our application.

// get the sp variable from the library
// this will serve as the root of our fluent chain
import { sp } from “@pnp/sp”;

// now get the web’s title
sp.web.select(“Title”).get().then(w => {
  console.log(`Title: ${w.Title}`);
});

The above is a basic example of what is possible – please check out the documentation for more details on all of the included libraries.

Get involved

There are several ways to get involved in working on the PnPJS libraries and we encourage anyone who is interested to reach out. You can submit a pull request to the git repository. We try and mark issues as help wanted when possible if you are looking for something to work on. Or join SharePoint Framework and client-side dev bi-weekly community calls where we cover topics related to these libraries as well as latest news on SharePoint framework, community demos, and other SharePoint Dev Patterns and Practices projects.

Feedback on the PnPJS libraries

We always appreciate feedback on our work, and with the launch of the PnPJS libraries, we want to renew our push for community involvement. If you find issues, have suggestions, or would like to submit a feature please open an issue. You can also post on the Microsoft Tech Community SharePoint Dev channel or reach out to us on twitter @officedevpnp if you have questions.

What is SharePoint Patterns and Practices?

SharePoint Patterns and Practices (PnP) is an open source initiative coordinated by SharePoint engineering. It’s a channel for the SharePoint engineering to share documentation, guidance, samples and reusable component for the community. PnP initiative coordinates all SharePoint developer documentation and guidance across on-premises and online. Day to day work is coordinated by the PnP Core team, which consists of Microsoft internal people and external MVPs. If you have any input or feedback around SharePoint developer guidance, don’t hesitate to start a discussion with the team at Microsoft Tech Community site at http://aka.ms/sppnp-community.

“Sharing is caring”


Patrick Rodgers, Senior Program Manager, Microsoft – 24th of January 2018