Applied APIs

Patrick Heneise

API and API Standards

API Recommended Practice 1160

Managing System Integrity for Hazardous Liquid Pipelines

Applied APIs

by Patrick Heneise

The boring part

The guy standing and talking: Patrick Heneise, @PatrickHeneise

"Full Stack JavaScript Architect with a focus on mobile"

Mobile Architect

#nodejs #nosql #couchbase #couchdb #redis #elasticsearch #api #iphone #android #firefoxos #phonegap #cordova

Why I'm standing here?

Because I care about APIs.

The important part;


  1. Security & Authentication
  2. API Methodologies
  3. Tracking & Analytics
  4. Error Handling
  5. Summary

Security & Authentication

Different types of authentication:

But OAuth2 is so complicated. Can I use ...


Implement OAuth2 right from the start, don't try to use anything else. You'll end up with it sooner or later anyway.*

* Until something else comes out.

API Methodologies

'Pulling' REST API

REST: The good

REST: The bad

Example: Tumblr

			Response: {

Don'ts: Tumblr

			"\u003C\/p\u003E\n\u003Cp\u003ECopa del Rey\u00a0"
Never return nonsense.

Pushing API

Push: The good

Push: The bad

Example: Instagram

curl -F 'client_id=CLIENT-ID' \
	-F 'client_secret=CLIENT-SECRET' \
	-F 'object=tag' \
	-F 'aspect=media' \
	-F 'object_id=nofilter' \
	-F 'callback_url=http://YOUR-CALLBACK/URL' \

Don'ts: Instagram

  "subscription_id": "1",
  "object": "user",
  "object_id": "1234",
  "changed_aspect": "media",
  "time": 1297286541
Never return nonsense.

More detailed...

  1. Response only returns the timestamp
  2. Media is not searchable by timestamp
  3. Go through recent media (unkown size)
  4. Parse until you found your last processed entry
  5. Go back to 1. when there's an update

Realtime Streaming API

Streaming: The good

Streaming: The bad

Example: Twitter

			Response: Full tweets

Don'ts: Twitter

Think of your customers

Analytics & Tracking

  1. BYOA [Booya] (Build Your Own Analytics)
  2. NewRelic
  3. Google Analytics

Redis Tracking

Hit count
ZINCRBY 'api:requests:2010-07-10' 1 'users#update'
Increment a Sorted Set of daily “Controller#Action” values by User ID:
ZINCRBY 'api:requests:2010-06-30:users#update' 1 1337
Add the current date to a Set of dates for which we’re tracking data:
SADD api:requests:dates '2010-07-10'

Big Data

Upload your Redis database and query with Amazon Redshift or Google BigQuery

Cheap, non-intrusive history without vendor lock-in.




Or: be smart, follow standards!

Example: BrainTree API

log(error, result);
null, ...

Example: BrainTree API

{ errors:
	{ validationErrors: {},
		errorCollections: { merchantAccount: [Object] } },
	{ merchantAccount:
			{ applicantDetails: [Object],
				tosAccepted: 'true',
				masterMerchantAccountId: 'xx',
				id: 'xx' },
		action: 'create_via_api',
		controller: 'merchant_accounts',
		merchantId: 'xx' },
	message: 'Master merchant account ID is invalid.',
	success: false }

The Excuse

An invalid account ID isn't a serious error.


So many things, just for an API?




Get in touch!