Reputation: 727
Firebase REST API doc has an example of posting a list of data:
curl -X POST -d '{
"author": "alanisawesome",
"title": "The Turing Machine"
}' 'https://docs-examples.firebaseio.com/rest/saving-data/fireblog/posts.json'
the keys are provided in the posted data. Is it possible to just post a list of values and have firebase auto-generate the keys, similar to the javascript example below?
var postsRef = ref.child("posts");
postsRef.push({
author: "gracehop",
title: "Announcing COBOL, a New Programming Language"
});
postsRef.push({
author: "alanisawesome",
title: "The Turing Machine"
});
Upvotes: 2
Views: 2937
Reputation: 599541
The Firebase REST API creates one child node for every POST request you send.
The JavaScript snippet you show does the same, it creates one child each time you call push
. It's just more efficient, since it only has to establish a connection once, while the REST API sets up a new connection for every request.
You can get the result you're looking for by generating the IDs client-side (the algorithm that Firebase uses to generate its Push IDs is described in this blog post) and then issuing a HTTP PATCH request.
Upvotes: 2