Upgrade to Pro — share decks privately, control downloads, hide ads and more …

From AdWords to Firebase: The Road to API Nirvana

From AdWords to Firebase: The Road to API Nirvana

More Decks by API Strategy & Practice Conference

Other Decks in Technology

Transcript

  1. From AdWords to Firebase The Road to API Nirvana Mandy

    Waite Developer Advocate at Google @tekgrrl
  2. @tekgrrl AdWords API Learnings • Errors can cost you money

    • Always be prepared to retry a failed call • A reasonable number of retries is fine • Avoid tight loops, use Exponential backoff • Log hard errors, monitor your severe errors When working with an API, Error handling should never be an afterthought
  3. @tekgrrl Google API Client Libraries Hard to auto-generate in a

    way that is idiomatic to the target language Different languages require different semantics in an API client Many languages have their own particular ways of solving problems A ‘simple’ transaction import googledatastore as datastore req = datastore.BeginTransactionRequest() key = datastore.Key() path = key.path_element.add() path.kind = 'Person' path.name = 'jim' resp = datastore.begin_transaction(req) tx = resp.transaction req = datastore.CommitRequest() req.transaction = tx entity = req.mutation.insert.add() entity.key.CopyFrom(key) prop = entity.property.add() prop.name = 'hometown' prop.value.string_value = 'New York' prop = entity.property.add() prop.name = age prop.value.integer_value = 40 datastore.commit(req)
  4. @tekgrrl gcloud client libraries Idiomatic rather than mapped Distributed through

    language-standard tools Community-owned code, issues, and docs gcloud client Authentication Auto-generated Developers
  5. @tekgrrl Transactions the Pythonic way from gcloud import datastore dataset

    = datastore.get_dataset(...) key = Key.from_path(['Person', 'jim']) entity = dataset.get_entity(key) with dataset.transaction(): entity[‘hometown’] = ‘New York’ entity[‘age’] = 40 entity.save() import googledatastore as datastore req = datastore.BeginTransactionRequest() key = datastore.Key() path = key.path_element.add() path.kind = 'Person' path.name = 'jim' resp = datastore.begin_transaction(req) tx = resp.transaction req = datastore.CommitRequest() req.transaction = tx entity = req.mutation.insert.add() entity.key.CopyFrom(key) prop = entity.property.add() prop.name = 'hometown' prop.value.string_value = 'New York' prop = entity.property.add() prop.name = age prop.value.integer_value = 40 datastore.commit(req)
  6. @tekgrrl • NoSQL, JSON database • Pushes updates in milliseconds

    when things change • Security model allows direct access from client devices • Maps each piece of data to a URL The Firebase Realtime Database Firebase can help
  7. @tekgrrl and it’s simple to code to Subtitle JavaScript var

    ref = new Firebase("https://<YOUR-FIREBASE>.firebaseio.com/welcome"); ref.set("Hello Berlin!"); ref.on(“value”, function(value) { var data = value.val(); console.log(data); // prints “Hello Berlin” and listens for // updates });
  8. @tekgrrl Start building 1 2 3 Go to cloud.google.com/free-trial $300

    in Cloud Platform credits to launch your idea! Build. Store. Analyze. On the same infrastructure that powers Google Sign up for the free trial Free Trial