Saving data to Firebase with REST

前端 未结 2 1641
北恋
北恋 2020-12-21 14:33

I\'m using Firebase to store application tokens with names, using the REST api.

This is the data structure I\'m using:

相关标签:
2条回答
  • 2020-12-21 15:08

    There are two ways:

    • if you want to add on row:

      method: PUT

      url: https://yourID.firebaseio.com/pages/your_object_name.json

      data:

      {
        "1": {
          "id": "5",
          "name": "page 4"
        }
      }
      
    • if you want to add multiple rows:

      methode: PATCH

      url: https://yourID.firebaseio.com/pages.json

      data:

      {
        "1": {
          "id": "5",
          "name": "page 4"
        },
        "2": {
          "id": "5",
          "name": "page 4"
        },
        "3": {
          "id": "5",
          "name": "page 4"
        }
      }
      
    0 讨论(0)
  • 2020-12-21 15:19

    You should put your self-generated ID into the URL:

    curl -X POST -d "{\":{\"name\":\"Test 2\"}" \ https://xxx.firebaseio.com/apps/3ba7792jae16328.json
    

    Firebase always overwrites (unless you use PATCH) the entire node at the URL you indicate. So it's important that you specify the URL up to the level that you want to overwrite data.

    0 讨论(0)
提交回复
热议问题