Watch out stretrieve datafiltering by a

Watch out stretrieve datafiltering by a

This preview shows page 34 - 49 out of 54 pages.

Watch out… st/retrieve-data#filtering-by-a-specified-child- key 34
Image of page 34
Example: filtering by child key curl '- 1b578.firebaseio.com/users.json?orderBy=" na me "&limitToFirst=1&print=pretty' What will this return? 35
Image of page 35
Example: filtering by value curl '- 1b578.firebaseio.com/student- scores/q1.json?orderBy="$ value "&limitToFirst =1&print=pretty' What will this return? 36
Image of page 36
Creating index for value/child key Specified in database rules: ty/indexing-data Only required for REST API 37
Image of page 37
Using REST in Python import requests May need to "pip install requests" first url = '- 1b578.firebaseio.com/users.json' response = requests. get (url) response.json() {u'200': {u'age': 25, u'name': u'David'},… 38
Image of page 38
Writing url1 = '- 1b578.firebaseio.com/users/888.json' data = '{"name": "jimmy", "sex": "male"}' response = requests. put (url1, data) 39
Image of page 39
Pretty printing import json print json.dumps(response.json(), indent=4) 40 { "200": { "age": 25, "name": "David" },
Image of page 40
Roadmap Firebase REST API Firebase Javascript/Web API Useful for your project 41
Image of page 41
42 Select this
Image of page 42
Copy the integration script 43
Image of page 43
A html page for testing 44 Internet explorer does not support "=>" notation Change it to function(snap) {…} val() returns a Javascript object representing content of snapshot
Image of page 44
Database reference Firebase.database() returns a reference to the firebase database as specified by "config" ref(): returns a reference to the root node of the database ref("weather") returns a reference to the "weather" child of the root same as ref().child("weather") 45
Image of page 45
Modify the data in database Observe the data automatically changed in the browser 46
Image of page 46
Write data using set() function writeUserData(userId, name, email) { firebase.database().ref("users/" + userId). set ({ name: name, email: email }); } writeUserData("123", "John", "[email protected]"); 47 Setting/overwriting the data of user 123
Image of page 47
Write data using push() and set() firebase.database().ref("users").push().set({na me: "John", email: "[email protected]"}); push() will automatically generate a key In this case, id for the new user Which REST command is this similar to?
Image of page 48
Image of page 49

You've reached the end of your free preview.

Want to read all 54 pages?

  • Fall '14
  • Representational State Transfer, Firebase, Firebase REST

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern

Stuck? We have tutors online 24/7 who can help you get unstuck.
A+ icon
Ask Expert Tutors You can ask You can ask You can ask (will expire )
Answers in as fast as 15 minutes