Skip to content

Commit 1cb0f74

Browse files
committed
Updated 2016-11-03-using-firebase-as-a-json-cache.md
1 parent 2e50314 commit 1cb0f74

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

_posts/2016-11-03-using-firebase-as-a-json-cache.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,23 @@ Make sure to set the rules, for debugging it can be a good idea to simply open u
2626
The next stage is for you server API to push to the Firebase Storage. Here is an example of PHP Laravel Middleware using the observer pattern to push JSON to firebase storage, the API is first calling itself to get the response and then caching it. The logic will be similar for different languages and frameworks.
2727

2828
~~~
29+
2930
$request = Request::create('/api/v2/sessiondata', 'GET');
3031
$userData = Route::dispatch($request);
3132
$json = $userData->getOriginalContent();
3233
3334
$client = new Client(); //GuzzleHttp\Client
3435
$firebaseResponse = $client->request('PUT', 'https://herokuapp174.firebaseio.com/data.json', ['json' => json_decode($json)]);
35-
~~~
36+
37+
~~~
3638

3739

3840
Finally the front-end application, whether you have a mobile app or a web application, needs to load the firebase plugin API and make a GET request to this https://herokuapp174.firebaseio.com/data.json. You may also need to authenticate correctly. The benefit of this system is that any encryption or expensive database calls are no longer made by the server, it's essentially a backup data store which pushes whenever an admin updated a route with the middleware attached.
3941

4042
Here is an example for an Angular app consuming the Firebase JSON cache with CryptoJS decryption so that the data is at least obfuscated:
4143

42-
~~~
44+
~~~
45+
4346
return $http.jsonp('https://herokuapp174.firebaseio.com/data.json?callback=JSON_CALLBACK')
4447
.success(function(response){
4548
@@ -52,5 +55,5 @@ $request = Request::create('/api/v2/sessiondata', 'GET');
5255
callback(data);
5356
5457
});
55-
~~~
56-
58+
59+
~~~

0 commit comments

Comments
 (0)