Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Push to Firebase via REST API with Priority

Tags:

firebase

Is it possible to use the REST API to push an event to a list (via an HTTP POST) and also specify the priority of the item that is being pushed? Perhaps as a field in the JSON I am posting somehow?

Something like this (semi-pseudo-code):

var myObj = {name: 'My Name', address: 'My Address'};
myObj['priority'] = 123;

$.post('http://demo.firebase.com/demo/testing.json', myObj);

I can do it the following way with the native Javascript library but this does not use the REST API:

var fb = new Firebase('http://demo.firebase.com/demo/testing');
var foo = fb.push({name: 'My Name', address: 'My Address'});
foo.setPriority(1);
like image 334
Matt Dodge Avatar asked Jun 07 '12 02:06

Matt Dodge


People also ask

Can I use REST API with Firebase?

We can use any Firebase Realtime Database URL as a REST endpoint. All we need to do is append . json to the end of the URL and send a request from our favorite HTTPS client.

Is Firebase good for push notifications?

Firebase Cloud Messaging (FCM) provides a reliable and battery-efficient connection between your server and devices that allows you to deliver and receive messages and notifications on iOS, Android, and the web at no cost.


1 Answers

Yes! To post data with a priority, you can use:

var myObj = JSON.stringify({name: 'My Name', address: 'My Address', '.priority': 123});
$.post('http://demo.firebase.com/demo/testing.json', myObj);

If you want to post a raw value (e.g. "hello") with a priority, use:

var myObj = JSON.stringify({'.value': 'hello', '.priority': 123});
$.post('http://demo.firebase.com/demo/testing.json', myObj);
like image 89
Michael Lehenbauer Avatar answered Sep 20 '22 22:09

Michael Lehenbauer