Sep 02 2016 01:47 PM
Sep 02 2016 01:47 PM
I rewrote my first REST library, presented at SPFest DC this year, in TypeScript and wanted to share the latest. It helps construct the url and transforms it if you are in the app web and reduces the number of calls to the server and code required to get work done.
Link to GitHub: SP REST
I hope this helps others out.
Sep 07 2016 06:19 AM
Nice tip @Gunjan Datta. Would you mind elaborating what the main benefits or differences are between your library and for example the perhaps more widely used Office PnP libraries for JS Core? (https://github.com/OfficeDev/PnP-JS-Core).
If there's things in your library that the JS core doesn't cover, perhaps there's an opportunity to enhance the core with some logic from your side as well.
Sep 07 2016 11:39 AM
+1 on @Tobias Zimmergren comment.
The SIG has a recurring weekly meeting in which your more than welcome to partipate and help furhter evolve the PnP-Core-JS library: http://aka.ms/officedevpnpofficehours
Sep 08 2016 03:05 PM - edited Sep 09 2016 02:18 PM
The library, also written in TypeScript, essentially builds the url via a mapper class and the metadata type. The documentation on my github site goes into detail of the library and has examples of all the objects you can create via 1 request.
Since you can switch between synchronous and asynchronous requests via a flag, I've been able to use the browser's console window and execute requests similar to powershell, when executing synchronous requests. This all runs under the context of the user executing the requests. This has been very useful when you do not have access to the farm, or need to execute a simple script. I don't believe, that the pnp-js-core has this type of feature.
Here is an example of creating a list asynchronously:
// This will create the web object, set the asynchronous flag and not execute a request to the server
// This will execute a request to the server to create a list
Description: "This is a test list.",
// This will execute after the list is created
// Additional code goes here
Here is an example of getting list items from a list/library:
// This will execute one request to the server to get list items
// new $REST.ListItems("[List Name]", "[View XML or CAML Query]");
// The query will default the parent to "<View>"
var items = new $REST.ListItems("Site Assets", "<Query><Where><Gt><FieldRef Name='ID' /><Value Type='Integer'>0</Value></Gt></Where></Query>");
var items = new $REST.ListItems("Site Assets", "<View Scope='RecursiveAll'><Query><Where><Eq><FieldRef Name='FileLeafRef' /><Value Type='File'>sprest.js</Value></Eq></Where></Query></View>");
Here is an example of getting the "sprest.js" file in the "Documents" list:
List: var file = new $REST.File("sprest.js", "documents");
Web: var file = new $REST.File("/sites/dev/shared documents/sprest.js");
Sep 08 2016 03:19 PM