APIs in Ruby

APIs in Ruby

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

1633e2784d925ea41167b45bccddcd19?s=128

Michael Cordell

June 04, 2015
Tweet

Transcript

  1. 4.

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

    ๏ Inputs ๏ Outputs ๏ Data-types ๏ How does your program interact with the outside world?
  2. 10.
  3. 15.

    json-schema.org ๏ JSON document that describes the structure of JSON

    data ๏ Moreover the schema itself is a JSON schema
  4. 19.

    { "title": "Dog", "type": "object", "properties": { "name": { "type":

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

    { "title": "Dog", "type": "object", "properties": { "name": { "type":

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

    { "title": "Dog", "type": "object", "properties": { "name": { "type":

    "string" }, "breed": { "type": "string" }, "license-number": { "description": "Municipal license number", "type": "integer", "minimum": 8 } }, "required": ["name"] }
  7. 22.

    { "title": "Dog", "type": "object", "properties": { "name": { "type":

    "string" }, "breed": { "type": "string" }, "license-number": { "description": "Municipal license number", "type": "integer", "minimum": 8 } }, "required": ["name"] }
  8. 26.

    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
  9. 29.

    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
  10. 32.

    ๏ Interrogable at runtime for docs ๏ Multiple formats: json,

    xml, txt, binary ๏ can support multiple at once ๏ Fairly good eco-system of supporting gems
  11. 38.
  12. 40.

    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)
  13. 41.

    Auth: JWT { "alg": "HS256", "typ": "JWT" } { "user":

    “Michael”, “email”: “mike@mikecordell.com, “admin”: 1 } Header Claims
  14. 44.

    Auth: JWT ๏ No DB call to verify user ๏

    Great for microservices ๏ Ruby library of course ๏ Hard to invalidate
  15. 49.

    Auto-generation ๏ Heroics ๏ json-schema -> ruby API Client ๏

    Textualize ๏ RAML -> spec/mock backend ๏ Pact ๏ Client/Service co-development & testing tool
  16. 51.

    Magic Night ๏ 4th Thursday of the Month ๏ LEARN

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