escape from the tower of babel - mike boufford, greenhouse

20
GREENHOUSE.I O Escape from the Tower of Babel or Using JSON-Schema to Enforce API Contracts @mboufford - Mike Boufford, VP of Engineering at Greenhouse

Upload: firstmark-capital

Post on 12-Apr-2017

310 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Escape from the Tower of Babel - Mike Boufford, Greenhouse

G R E E N H O U S E . IO

Escape from the Tower of Babelor Using JSON-Schema to Enforce API Contracts

@mboufford - Mike Boufford, VP of Engineering at Greenhouse

Page 2: Escape from the Tower of Babel - Mike Boufford, Greenhouse

What we’ll talk about

Primarily• Foxclores• Luzodins• Maozblitzers

But, also!• Norristronomy*• Fuffapesterinos• and of course, Hawkoons

Page 3: Escape from the Tower of Babel - Mike Boufford, Greenhouse

I’ll presume that you’re all familiar with those terms?

Page 4: Escape from the Tower of Babel - Mike Boufford, Greenhouse

Our APIs are all speaking a Glossopoeia!

Page 5: Escape from the Tower of Babel - Mike Boufford, Greenhouse

A brief history of Schemata

• Schema comes from the Greek skhēma which translates to “form”

• The great German philosopher Kant took the term to mean “a conception of what is common to all members of a class"

Page 6: Escape from the Tower of Babel - Mike Boufford, Greenhouse

1996: The Internet’s Rumspringa

Page 7: Escape from the Tower of Babel - Mike Boufford, Greenhouse

D o u g l a s C r o c k f o r dDiscoverer of JSON and opinionated linter

{ something: “Blargh!” }

“Hey! Look what I found! We can

use this to send data on the

Internets!”

Page 8: Escape from the Tower of Babel - Mike Boufford, Greenhouse

:-(

Um…Now I have to write adapters for everything I receive from anyone else, forever and ever.On the upside: #jobsecurity!

Page 9: Escape from the Tower of Babel - Mike Boufford, Greenhouse

We now live in a world that is hostile to schemata

Page 10: Escape from the Tower of Babel - Mike Boufford, Greenhouse

Stop the insanity!Itigil ni ito pagkabaliw Hayaan.

এর এই পাগলািম বn করা যাক .

Давайце спынім гэта вар'яцтва .

让我们停⽌止这种疯狂。

. בואו נעצור הטירוף הזה

ဒ" #$%သ'ပ)*ခင)% ကiuရပ)တ2)3 4ကကuန)အ73။Pojďme se zastavit toto šílenství .

. اس پاگلپن کو روکنے کے ہیں

Page 11: Escape from the Tower of Babel - Mike Boufford, Greenhouse

First Step:

Teach people JSON-Schema

1JSON-Schema is a composable JSON-based schema language. It looks like this:

{

‘$schema’: ‘http://foo.com/person-01/schema’,

‘type’: ‘object’,

‘properties’: {

‘first_name’: { ‘type’: ‘string’ },

‘last_name’: { ‘type’: ‘string’ }

},

‘required’: [ ‘first_name’, ‘last_name’ ]

}

Page 12: Escape from the Tower of Babel - Mike Boufford, Greenhouse

Composability {

‘$schema’: ‘http://foo.com/user-01/schema’,

‘type’: ‘object’,

‘properties’: {

‘user_id’: { ‘type’: ‘number’ },

‘person’: {

‘$ref’: ‘http://foo.com/person-01/schema’

}

},

‘required’: [ ‘user_id’, ‘person’ ]

}

Keeping things DRY

Page 13: Escape from the Tower of Babel - Mike Boufford, Greenhouse

Simple{ ‘http_status_code’: { ‘type’: ‘string’ } }

Page 14: Escape from the Tower of Babel - Mike Boufford, Greenhouse

Validation{ ‘http_status_code’: {

‘type’: ‘string’,

‘pattern’: ‘^[0-9]{3}$’

} }

Page 15: Escape from the Tower of Babel - Mike Boufford, Greenhouse

Validation { ‘http_status_code’: {

‘type’: ‘number’,

‘enum’: [ 200, 403, 500 ]

} }

Part Deux

{ ‘http_status_code’: 500 }

Page 16: Escape from the Tower of Babel - Mike Boufford, Greenhouse

Automated API Tests

Page 17: Escape from the Tower of Babel - Mike Boufford, Greenhouse

JSON Hyper-Schema!

Enforcing RESTfulnessAnd we ain’t talking about nap time.

Page 18: Escape from the Tower of Babel - Mike Boufford, Greenhouse

e.g., {

"href": “/apples“,

"method": "POST",

"rel": "self",

"targetSchema": {

"$ref": “http://foo.com/apple-schema#",

}

}

HYPER! AHHH!

Page 19: Escape from the Tower of Babel - Mike Boufford, Greenhouse

So Dang EZ! What’s the catch?

Page 20: Escape from the Tower of Babel - Mike Boufford, Greenhouse

Thank you.