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

APIs in Ruby

APIs in Ruby

Explores the landscape of API tooling in Ruby. Presented at SDRuby

Michael Cordell

June 04, 2015
Tweet

More Decks by Michael Cordell

Other Decks in Programming

Transcript

  1. What and Why ๏ Application programming interface (API) ๏ Operations

    ๏ Inputs ๏ Outputs ๏ Data-types ๏ How does your program interact with the outside world?
  2. json-schema.org ๏ JSON document that describes the structure of JSON

    data ๏ Moreover the schema itself is a JSON schema
  3. { "title": "Dog", "type": "object", "properties": { "name": { "type":

    "string" }, "breed": { "type": "string" }, "license-number": { "description": "Municipal license number", "type": "integer", "minimum": 8 } }, "required": ["name"] }
  4. { "title": "Dog", "type": "object", "properties": { "name": { "type":

    "string" }, "breed": { "type": "string" }, "license-number": { "description": "Municipal license number", "type": "integer", "minimum": 8 } }, "required": ["name"] }
  5. { "title": "Dog", "type": "object", "properties": { "name": { "type":

    "string" }, "breed": { "type": "string" }, "license-number": { "description": "Municipal license number", "type": "integer", "minimum": 8 } }, "required": ["name"] }
  6. { "title": "Dog", "type": "object", "properties": { "name": { "type":

    "string" }, "breed": { "type": "string" }, "license-number": { "description": "Municipal license number", "type": "integer", "minimum": 8 } }, "required": ["name"] }
  7. Interface Libraries ๏ Slim down version of the rails stack

    ๏ Key selling points: ๏ Lessons already learned (security) ๏ Dev environment and tooling ๏ Param parsing and other routing niceties rails-api
  8. curl http://localhost:9292/statuses/public_timeline?apiver=v1 Version by Param curl -H “Accept-Version:v1" http://localhost:9292/v1/comments Version

    by Accept-version header curl -H Accept:application/vnd.some-v1+json http://localhost: 9292/v1/comments Version by Header curl http://localhost:9292/v1/comments Version by path
  9. ๏ Interrogable at runtime for docs ๏ Multiple formats: json,

    xml, txt, binary ๏ can support multiple at once ๏ Fairly good eco-system of supporting gems
  10. Auth JSON Web Token (JWT) is a compact URL-safe means

    of representing claims to be transferred between two parties. The claims in a JWT are encoded as a JSON object that is digitally signed using JSON Web Signature (JWS)
  11. Auth: JWT { "alg": "HS256", "typ": "JWT" } { "user":

    “Michael”, “email”: “[email protected], “admin”: 1 } Header Claims
  12. Auth: JWT ๏ No DB call to verify user ๏

    Great for microservices ๏ Ruby library of course ๏ Hard to invalidate
  13. Auto-generation ๏ Heroics ๏ json-schema -> ruby API Client ๏

    Textualize ๏ RAML -> spec/mock backend ๏ Pact ๏ Client/Service co-development & testing tool
  14. Magic Night ๏ 4th Thursday of the Month ๏ LEARN

    ๏ 3803 Ray St, San Diego, CA ๏ Its on meetup.com