$curl-X GET 'https://rest-apidemo.firebaseio.com/address/city.json'return: "New York"% -X 可以省略 直接 curl GET url; GET 可以省略 直接 curl url
$curl'https://rest-apidemo.firebaseio.com/phoneNumbers/0.json'#refer to arr element by index return:{"number":"212 555-1234","type":"home"}%
PUT: write a given value (e.g., “Mary”) to a specify node (e.g., “spouse”)
1 2 3 4 5 6 7 8 9
Add if nodenot exists (could add embedded nodes) - 添加数据 Overwrite if nodealready has value - 重写数据
$ curl -X PUT 'https://rest-apidemo.firebaseio.com/spouse.json' -d '"Mary"' # 注意引号
#This will add a new node "country" (assuming it does not exist yet) #and a child of this node with key "province" and content: {"name": "Anhui"} $ curl -X PUT 'https://rest-apidemo.firebaseio.com/country/province.json' -d '{"name": "Anhui"}' $ curl -X PUT 'https://rest-apidemo.firebaseio.com/country.json' -d '{"province": {"name": "Anhui"}}'
POST: add new value to a given node
1 2 3 4 5
Automatically generates a newkey & then stores the value for the newkey 由于对于添加的数据,其自动生成一个key,所以保证不会重写数据(In contrast, PUT will simply overwrite the key)
$ curl -X POST 'https://rest-apidemo.firebaseio.com/country.json' -d '{"province": {"name": "Anhui"}}' $ curl -X POST 'https://rest-apidemo.firebaseio.com/country.json' -d '"Anhui"'
PATCH: upsert a value to a given node
1 2 3 4 5 6 7 8 9 10 11 12 13 14
Performs the updateifvalue already exists -更新节点 Otherwise, it inserts the newvalue -插入新节点 PATCH本质上是一个深度搜索符合节点的条件进行更新或者添加)
curl -X GET 'https://rest-apidemo.firebaseio.com/scores.json?orderBy="$key"&equalTo="1"' curl -X GET 'https://rest-apidemo.firebaseio.com/scores.json?orderBy="$key"&startAt="1"' curl -X GET 'https://rest-apidemo.firebaseio.com/scores.json?orderBy="$value"'