Saturday, September 24, 2016

Better SharePoint Framework Code with SPRemoteAPI 1.5 VSCode Extension

I have been working with the new SharePoint Framework for the last month. This is the new Microsoft framework for SharePoint developers which makes it incredibly easily create web parts and web page applications using Typescript and other web technologies. I highly recommend switching to VSCode from Visual Studio when using this framework since it has greater flexibility for working with open source web technologies. The new framework relies heavily on the use of Typescript which gives you the ability to generate JavaScript code with compile time type checking along with intellisense to see available properties and methods while typing code.

SPRemoteAPI VSCode Extesnion

If you have ever worked with the SharePoint/O365 REST API you know that it is not easy to discover what types, methods and properties are available to you. When writing Typescript code you should always define your interfaces for REST responses and requests. The interfaces enable you to declare types which enables intellisense and type checking. Usually there are Typescript declaration files available for many framework libraries. The SharePoint REST API is not one of them. There are Typescript declarations for the SharePoint JavaScript Object Model but they are not kept up to date and do not match the REST API. It can be incredibly tedious to find REST example code and then go and create an interface for the request and response. Many developers will just create an interface and do some mapping from the REST response to a custom interface. This involves making the REST call and then examining the response to determine how to do the mapping.

SPRemoteAPI 1.5 Supports Creating Typescript Interfaces

Well I got tired of the error prone and laborious process of creating interfaces for the SharePoint REST API. I wanted something that would generate the interface for me that would automatically and exactly map to the response or request for a REST call. Many of the responses and request objects have properties that expose other complex types, so I wanted something that would create all the interfaces required to handle a response and request. So all you have to do is invoke the extension, then search for the type and click the “Create Interface” button.

After clicking the button all the interfaces that are exposed by the this type are created and put into the virtual declaration file. Since this file is virtual, you can then just copy whatever you want from this to your own declaration file. The “Create Interface” button is only visible on types that have properties. All properties are optional giving you the ability to choose which properties you use.

Once you have added this to a Typescript file and added an import statement you can now declare a type and get type checking along with intellisense for SharePoint REST response or request.

Get Productive with Intellisense and Type Checking

This feature will save you a lot of time having to research REST requests and responses. It will help you get up to speed on the SharePoint REST API and using the new SharePoint Framework. Enjoy.

Monday, July 4, 2016

Visual Studio Code Extension–SPRemoteAPI (SharePoint Office 365 REST API Discovery for the Masses)

Technorati Tags: ,,,

For everyone who has ever used the Visual Studio extension SPRemoteAPIExplorer one of the pain points is the requirement that you had have SharePoint installed on the same box as Visual Studio. Now you can get the same basic functionality of being able to browse and discover what is available in SharePoint and Office 365 REST and JavaScript API without having to have SharePoint installed. You can type in a namespace and browse the methods and properties. You can determine if they are available to be used with REST and JavaScript. You can also see what is new in SharePoint 2016. Finally when looking at specific methods or functions the extension gives the required POST bodies and response payloads, allowing the developer to easily copy and paste this into his code. You can get the VSCode extension here SPRemoteAPI in the Visual Studio Market Place. Oh did I mention it is FREE.

Using SPRemoteAPI Extension (Step 1)

In VSCode just hit F1 and start typing SPRemoteAPI and you will see it appear in the drop down list.


Using SPRemoteAPI Extension (Step 2)

After selecting the SPRemoteAPI command you will be presented with all the available types in the SharePoint Office 365 remote API. You can start typing and the list will automatically filter as you type. The example below shows typing “move” and the list is filtered down to types with the word move contained in them. This list shows a github icon (flame) next to types that are new in SharePoint 2016. It also lists whether the type can be used in REST or JavaScript. Some types are not available for both.

Using SPRemoteAPI Extension (Step 3)

Once you selected the type you are presented a information dialog showing you the type along with options for displaying properties and methods. The options also shows you the number of each contained in the type.

Using SPRemoteAPI Extension (Step 4)

Select the methods options and you are presented a list of available methods to choose from.

Using SPRemoteAPI Extension (Step 5)

Choose a method and a new code window (virtual document) opened containing a JSON representation of all the method’s information needed to call it remotely using REST. It shows you the parameter types, required post body and response body. The post body can be copied into whatever REST calling framework you are using such as FETCH or JQuery. The response can be used to guide you in what to expect in the payload response from the call. This gives you ability to write remote REST calls without having to do all the extra experimentation to see what the call returns. Having both the body and response JSON templates will save you a lot of time searching on the internet.

What about properties?

Below is example of the code window you are given when you select properties. It shows you all the available properties for the type and the information you need to determine what is available remotely from SharePoint Office 365.

SPRemoteAPI in Action


SPRemoteAPI VSCode Extension – SharePoint Office 365 REST Discovery at your fingertips

This Visual Studio Code extension was created to open up the SharePoint Office 365 remote API to the many developers who do not use Visual Studio to develop. This extension will run on non-windows environments and of course does not require SharePoint to be installed locally. You can now easily figure out what is available and how to call any SharePoint REST API without having to search and page through mounds of documentation. Enjoy being productive!