Sharepoint - In SPFx, do I use CSOM, REST or something else?

For REST-queries, you should use the SpHttpClient class. JSOM is no longer being maintained, so avoid it for now.

For "back-end" (C#-code), CSOM is your only option. I usually deploy some CSOM code by using an Azure function and loading the SharePointPnPCoreOnline library. It's easy and fast to set up. The main benefit of the PnP library is the ClientContext.ExecuteQueryRetry()-function which has a built in retry-strategy if your requests get throttled.


In SPFx you get page context automatically. With page context you can get Site context and all the elements like list, libraries. In SPFx we have to use javascript frameworks like Node.js, React, Angular. You have to get data from SP using REST calls with using one of these javascript frame works. Hope this helps you.


There are multiple options you can use in SPFx:

  • SPHttpClient class to make REST requests to SharePoint REST API
  • You can also load any JSOM files to the page (by default, they're not loaded on modern pages). This could be helpful if you need to perform some operations that are unavailable in REST
  • GraphHttpClient or AadHttpClient to perform MS Graph requests
  • PnP libs to perform SharePoint REST calls using JavaScript objects

Tags:

Spfx