How do I avoid preloading the same data multiple times in a Sapper app? - server-side-rendering

I am new to Sapper and am trying to figure out how to handle data from an API that should be shared across multiple routes.
Take for example a logged in user object from an API. There are multiple routes where I would need this data and want it to be preloaded, but don't want to fetch the data from my API more than once (I believe I am right in thinking that the preload function will run on each page navigation).
In an SPA built with plain Svelte, I would fetch this kind of data once on the client and use a store to share the data between the pages.
It doesn't seem possible to access stores in my preload function, so how do I share this data between routes?

Related

System API design - questions

We're designing a new service orchestrator which will provide a multi-staged flow for the user and will be communicating with several foreign services internally.
I'm preparing API for it and I have a few questions:
The main flow will constitute of several web pages and each one of them will contain unique information extracted from several sources. Should we set several different API endpoints for each page or it's better to create a single endpoint which would internally decide what logic to execute based on stage/page number?
Is it ok to use POST requests for those endpoints where we could use GET, but the data there is ever-changing? I'm concerned about caching when I don't want to. Though I can always explicitly disable caching.

How to save data to REST API using a calculated model

I'm building a UI in Google Appmaker to manage the Domain Shared Contacts API. I can read and display data from the API in appmaker using a calculated model, but I cannot save data back into the API.
I tried adding a form widget with the calculated model as a datasource, but this is a read / view only form. This is when i found out calculated data sources are always read-only in app maker.
I then created an SQL datasource and made an event that queries the Domain Shared Contact API which then creates records and saves them to the SQL Model. I was thinking about using the standard form widget and then in the events beforeSave, beforeDelete, etc to write the record to the API.
However this feels dirty to me, since now I have to keep the SQL model synchronized with the API, need to have an SQL server running, etc.
Does anyone have any tips on the best way to write data from a form in appmaker to a REST API? I can't be only one with this use case.
You have to write app script function for this. https://developers.google.com/apps-script/reference/url-fetch/url-fetch-app

Can I fire a cloud function from Firebase Hosting after the page has loaded?

I'd like to create a website hosted by Firebase Hosting, which can post/put/get data from a Firebase Database. Google's example to connect Hosting to a Database isn't very helpful to me though, because it doesn't give any indication of how to fire a cloud function AFTER the page has loaded (the example fires a cloud function whenever you go to a specific url and fires when that page loads).
The most similar SO post I could find was this one, which appears to be able to interact with a database after the page loads like I want, my difference is that I want the interaction to be server-side (I want as little information about how the data is stored as possible to be shown).
I'm thinking if I can fire a cloud function after the page has loaded (when a user hit's a save button), that cloud function can interact with the database through an API to save the information.
In my searching I couldn't find very much information about connecting Firebase like this, is this possible/logical?
It sounds like all you need to do is create an HTTP trigger, then call that from a XMLHTTPRequest or similar. You can do that whenever you want from the page that's currently showing in the browser.
Cloud Functions code don't need to be interacting with the database via a REST interface. They should just be using the Admin SDK instead, which is far easier and faster. There are a lot of official samples that illustrate this.

using HTML5 session storage in asp.net mvc3

Explanation of the problem:
Right now my asp.net mvc 3 application is using cookieles="auto" setting which I really hate and I am trying to find something that will allow me to turn that feature off.
So I came across HTML5 storage solutions and I am having some trouble understanding the idea behind it. So basically all I need to do is take my userID variable and move it from one page to another and then on the backend I pull out this userID and pass data to view as a model. Now, how can I do it without cookies and using HTML5 storage? If it's only accessible via JavaScript do I need to pass it via ajax to my controllers? But I don't see any sense in this since I already passed my model to the view with empty userID because the cookie was empty.
Is there a way to access the HTML5 storage in the backend? Maybe I am missing something here, please advise!
No, there's no way except javascript code, which will read storage content and send it to backend. For small portion of data, which should be available to the server, use cookies.
Local storage was created specially for content, which will not be transfered to the server with each request and therefore allowing to store more data, than cookies w/o traffic spoiling.

Passing calculated data over a WCF service layer for reporting

I'm not really sure how to best word this. We have an ASP.NET web application with the backend services accessible over a WCF service layer. We need to add some reporting/dashboard type bits to the web application.
To make it scalable the data needed for the reporting needs to be calculated on the backend. I'm just wondering if there is a recommended way to pass this data around. It doesn't make much sense to have different service methods to get the different bits of data, it feels like it should be summarised already.
I had a look at WCF Data Services, but that seems more for retrieving full object trees. Maybe some sort of XML document so extra items can be added to the summary without needing service layer changes?
The data would be things like number of orders today, number of orders specific to the person running it, open orders outstanding etc.
Does anyone have any pointers?
Thanks for your time
You can look at something like ASP.NET Web API and use an XML Formatter for your data. You can use ViewModels to flatten your data and send over the wire to your web app to bind to grids or whatever you need to.
Basically you would get request (filters, keywords, etc) from your web app, send the parameters to your reporting back-end, retrieve the reporting data, map the values to your ViewModels and serialize them using Web API. Using Web API you can use all kinds of formatters for your data to XML, CSV and JSON to vCard, iCal, PDF, etc...
You can read more about it here: http://www.asp.net/web-api

Resources