koltyakov / sp-rest-proxy

🌐 SharePoint API Proxy for local development
MIT License
172 stars 43 forks source link

Add a client example? #14

Closed brucelane closed 7 years ago

brucelane commented 7 years ago

Hi, It would be nice to have another example for a nodejs project which uses this npm module, without using Express nor JQuery. Because now we use : var restProxy = new RestProxy(settings); restProxy.serve(); We get your html page using JQuery, which is good for testing. But I would like to use sp-rest-proxy to create a REST API in my own nodejs sharepoint client project. Thank you Bruce

koltyakov commented 7 years ago

Hi Bruce,

Could you please elaborate your use case scenario?

We usually run a proxy in serve mode along or independently from the project, point the requests to the proxy's URL during the development cycle. This lets boosting with processes of SPA development without publishing anything to SharePoint or referencing to localhost'ed assets.

In such scenario, any http library (Axios, Fetch, jQuery.ajax, xhr, $http, etc.) can consume the service (with cross-domain origin requests nuances in mind). And one could not think about SharePoint auth related staff, just business logic.

After the development cycle, the code is published for hosting and living inside SharePoint pages context. The requests are routed to _spPageContextInfo.

Also, sp-rest-proxy can be integrated to the end project with settings pointing to your front-end files (settings.staticRoot).

-- Andrew

brucelane commented 7 years ago

My first use case is to get data from a Sharepoint list into a nodejs microservices server to be used in a REST client (reactjs).

Later on, I would add CRUD operations.

koltyakov commented 7 years ago

So your project is a microservice API and it attends to run in NodeJS environment in production? Not only while the development stage?

If so, there is a nice way to deal with such case with the use of sp-request, which, btw, is also used in sp-rest-proxy.

Where is your React client-app living? Outside SharePoint? Is the microservice in charge of users authentication too?

brucelane commented 7 years ago

yes, development and production. I will have a look at sp-request, for what I read it seems to handle authentication and modern javascript too! The ReactJs / React-Native apps will be used outside Sharepoint, I create those microservices to create a json cache for SP lists because I will do server-side rendering and/or store the json files in the apps. It's to store towns' road names, which don't get updated that often...

For the Update part, which is later, I would need to authenticate the users... but I'm not there yet

koltyakov commented 7 years ago

Got it!

Yep, I would recommend using sp-request and wrapping requests to SharePoint in your NodeJS API. This allows you to separate API access to the specific operations. sp-rest-proxy abstracts access layer to SharePoint. And any request to SharePoint tenant executes under provided service account. It's wonderful when the proxy extends development toolchain, but a not what is expected from a secure microservice in production. The idea behind the proxy is for slightly different things (dev toolchain, CI).

brucelane commented 7 years ago

Thank you very much, very helpful! Have a nice day Andrew!

koltyakov commented 7 years ago

Cheers! Any questions about sp-request and node-sp-auth are welcomed.