SlideShare une entreprise Scribd logo
1  sur  22
Télécharger pour lire hors ligne
BLDR
                             Minimalist JSON templating DSL

                                      Alex Sharp
                                      @ajsharp


Friday, September 30, 2011
WHO AM I?

       Alex Sharp (@ajsharp)

       Ruby Engineer at Zaarly (zaarly.com)




Friday, September 30, 2011
WHAT IS ZAARLY?

       Buyer-centric local commerce platform

       Heavily api driven (iOS, Android, Web, HTML5 mobile)

       API only speaks json




Friday, September 30, 2011
WHY BLDR?




Friday, September 30, 2011
LET ME COUNT THE REASONS

       #as_json quickly gets...unwieldy

       We need tight control over our json responses




Friday, September 30, 2011
SECURITY EXPLOIT

       We were leaking information in our json documents we
       weren’t aware of

       We didn’t understand #as_json was recursing through
       relationships and serializing them

       Not good...




Friday, September 30, 2011
TECHCRUNCH STORY




Friday, September 30, 2011
BLDR

       We wanted a simple, declarative DSL for defining JSON
       responses




Friday, September 30, 2011
BLDR

       Simple, declarative DSL

       Works with Sinatra

       Rails 3 support nearly complete

       Four DSL methods (object, collection, attribute, attributes)




Friday, September 30, 2011
SINATRA

     get '/foo' do
       bar = 'baz'
       bldr :foo, :locals => {:bar => bar}
     end




Friday, September 30, 2011
SINATRA

        # foo.bldr
        object do
          attribute :foo, bar
        end

        # output
        {"foo": "baz"}


Friday, September 30, 2011
ATTRIBUTE LISTS
           object :post => post do
             attributes :title, :body
           end

           { "post": {
               "title": "my title",
               "body": "..."
             }
           }
Friday, September 30, 2011
IMPLIED OBJECTS
           object :post do
             attributes :title, :body
           end

           { "post": {
               "title": "my title",
               "body": "..."
             }
           }
Friday, September 30, 2011
DYNAMIC ATTRIBUTES
       object :post do
         attribute :comment_count do |post|
           post.comments.count
         end
       end

       { "post": {"comment_count":1} }



Friday, September 30, 2011
OBJECT NESTING
     object :post => post do
       attributes :title, :body

       object :author => post.author do
         attribute :last_name
       end
     end

     { "post": {
         "title": "my title",
         "body": "...",
         "author": {"last_name": "Doe"}
       }
     }
Friday, September 30, 2011
ATTRIBUTE ALIASES
     object :post => post do
       attributes :title, :body

       object :author => post.author do
         attribute :surname => :last_name
       end
     end

     { "post": {
         "title": "my title",
         "body": "...",
         "author": {"surname": "Doe"}
       }
     }
Friday, September 30, 2011
TOP-LEVEL COLLECTIONS
   collection :posts => posts do
     attributes :title, :body
     attribute :comment_count { |post| post.comments.count }
   end



      { "posts": [
         { "title": "my title",
           "comment_count": 2,
         }
      ]}



Friday, September 30, 2011
NESTED COLLECTIONS
      collection :posts => posts do
        collection :comments => current_object.comments do
          attributes :body, :author, :email
        end
      end
     { "posts": [
        { "comments": [
            { "body": "...",
              "author_name": "Comment Troll",
              "email": "troll@trolling.edu" }
        ]}
     ]}


Friday, September 30, 2011
OTHER FEATURES

       Uses multi_json gem -- pick your encoding library

       Bldr.handler




Friday, September 30, 2011
Bldr.handler BSON::ObjectId do |value|
      val.to_s # => "4e77a682364141ecf5000002"
    end




Friday, September 30, 2011
MORE INFO




Friday, September 30, 2011
MORE INFO

       github.com/ajsharp/bldr

       @ajsharp

       ajsharp@gmail.com

       zaarly.com / alexjsharp.com




Friday, September 30, 2011

Contenu connexe

Plus de Alex Sharp

Bldr: A Minimalist JSON Templating DSL
Bldr: A Minimalist JSON Templating DSLBldr: A Minimalist JSON Templating DSL
Bldr: A Minimalist JSON Templating DSLAlex Sharp
 
Mysql to mongo
Mysql to mongoMysql to mongo
Mysql to mongoAlex Sharp
 
Refactoring in Practice - Sunnyconf 2010
Refactoring in Practice - Sunnyconf 2010Refactoring in Practice - Sunnyconf 2010
Refactoring in Practice - Sunnyconf 2010Alex Sharp
 
Refactoring in Practice - Ruby Hoedown 2010
Refactoring in Practice - Ruby Hoedown 2010Refactoring in Practice - Ruby Hoedown 2010
Refactoring in Practice - Ruby Hoedown 2010Alex Sharp
 
Practical Ruby Projects with MongoDB - Ruby Kaigi 2010
Practical Ruby Projects with MongoDB - Ruby Kaigi 2010Practical Ruby Projects with MongoDB - Ruby Kaigi 2010
Practical Ruby Projects with MongoDB - Ruby Kaigi 2010Alex Sharp
 
Practical Ruby Projects with MongoDB - Ruby Midwest
Practical Ruby Projects with MongoDB - Ruby MidwestPractical Ruby Projects with MongoDB - Ruby Midwest
Practical Ruby Projects with MongoDB - Ruby MidwestAlex Sharp
 
Practical Ruby Projects with MongoDB - MongoSF
Practical Ruby Projects with MongoDB - MongoSFPractical Ruby Projects with MongoDB - MongoSF
Practical Ruby Projects with MongoDB - MongoSFAlex Sharp
 
Practical Ruby Projects With Mongo Db
Practical Ruby Projects With Mongo DbPractical Ruby Projects With Mongo Db
Practical Ruby Projects With Mongo DbAlex Sharp
 
Intro To MongoDB
Intro To MongoDBIntro To MongoDB
Intro To MongoDBAlex Sharp
 
Getting Comfortable with BDD
Getting Comfortable with BDDGetting Comfortable with BDD
Getting Comfortable with BDDAlex Sharp
 
Testing Has Many Purposes
Testing Has Many PurposesTesting Has Many Purposes
Testing Has Many PurposesAlex Sharp
 

Plus de Alex Sharp (11)

Bldr: A Minimalist JSON Templating DSL
Bldr: A Minimalist JSON Templating DSLBldr: A Minimalist JSON Templating DSL
Bldr: A Minimalist JSON Templating DSL
 
Mysql to mongo
Mysql to mongoMysql to mongo
Mysql to mongo
 
Refactoring in Practice - Sunnyconf 2010
Refactoring in Practice - Sunnyconf 2010Refactoring in Practice - Sunnyconf 2010
Refactoring in Practice - Sunnyconf 2010
 
Refactoring in Practice - Ruby Hoedown 2010
Refactoring in Practice - Ruby Hoedown 2010Refactoring in Practice - Ruby Hoedown 2010
Refactoring in Practice - Ruby Hoedown 2010
 
Practical Ruby Projects with MongoDB - Ruby Kaigi 2010
Practical Ruby Projects with MongoDB - Ruby Kaigi 2010Practical Ruby Projects with MongoDB - Ruby Kaigi 2010
Practical Ruby Projects with MongoDB - Ruby Kaigi 2010
 
Practical Ruby Projects with MongoDB - Ruby Midwest
Practical Ruby Projects with MongoDB - Ruby MidwestPractical Ruby Projects with MongoDB - Ruby Midwest
Practical Ruby Projects with MongoDB - Ruby Midwest
 
Practical Ruby Projects with MongoDB - MongoSF
Practical Ruby Projects with MongoDB - MongoSFPractical Ruby Projects with MongoDB - MongoSF
Practical Ruby Projects with MongoDB - MongoSF
 
Practical Ruby Projects With Mongo Db
Practical Ruby Projects With Mongo DbPractical Ruby Projects With Mongo Db
Practical Ruby Projects With Mongo Db
 
Intro To MongoDB
Intro To MongoDBIntro To MongoDB
Intro To MongoDB
 
Getting Comfortable with BDD
Getting Comfortable with BDDGetting Comfortable with BDD
Getting Comfortable with BDD
 
Testing Has Many Purposes
Testing Has Many PurposesTesting Has Many Purposes
Testing Has Many Purposes
 

Dernier

Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 

Dernier (20)

Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 

Bldr - Rubyconf 2011 Lightning Talk

  • 1. BLDR Minimalist JSON templating DSL Alex Sharp @ajsharp Friday, September 30, 2011
  • 2. WHO AM I? Alex Sharp (@ajsharp) Ruby Engineer at Zaarly (zaarly.com) Friday, September 30, 2011
  • 3. WHAT IS ZAARLY? Buyer-centric local commerce platform Heavily api driven (iOS, Android, Web, HTML5 mobile) API only speaks json Friday, September 30, 2011
  • 5. LET ME COUNT THE REASONS #as_json quickly gets...unwieldy We need tight control over our json responses Friday, September 30, 2011
  • 6. SECURITY EXPLOIT We were leaking information in our json documents we weren’t aware of We didn’t understand #as_json was recursing through relationships and serializing them Not good... Friday, September 30, 2011
  • 8. BLDR We wanted a simple, declarative DSL for defining JSON responses Friday, September 30, 2011
  • 9. BLDR Simple, declarative DSL Works with Sinatra Rails 3 support nearly complete Four DSL methods (object, collection, attribute, attributes) Friday, September 30, 2011
  • 10. SINATRA get '/foo' do bar = 'baz' bldr :foo, :locals => {:bar => bar} end Friday, September 30, 2011
  • 11. SINATRA # foo.bldr object do attribute :foo, bar end # output {"foo": "baz"} Friday, September 30, 2011
  • 12. ATTRIBUTE LISTS object :post => post do attributes :title, :body end { "post": { "title": "my title", "body": "..." } } Friday, September 30, 2011
  • 13. IMPLIED OBJECTS object :post do attributes :title, :body end { "post": { "title": "my title", "body": "..." } } Friday, September 30, 2011
  • 14. DYNAMIC ATTRIBUTES object :post do attribute :comment_count do |post| post.comments.count end end { "post": {"comment_count":1} } Friday, September 30, 2011
  • 15. OBJECT NESTING object :post => post do attributes :title, :body object :author => post.author do attribute :last_name end end { "post": { "title": "my title", "body": "...", "author": {"last_name": "Doe"} } } Friday, September 30, 2011
  • 16. ATTRIBUTE ALIASES object :post => post do attributes :title, :body object :author => post.author do attribute :surname => :last_name end end { "post": { "title": "my title", "body": "...", "author": {"surname": "Doe"} } } Friday, September 30, 2011
  • 17. TOP-LEVEL COLLECTIONS collection :posts => posts do attributes :title, :body attribute :comment_count { |post| post.comments.count } end { "posts": [ { "title": "my title", "comment_count": 2, } ]} Friday, September 30, 2011
  • 18. NESTED COLLECTIONS collection :posts => posts do collection :comments => current_object.comments do attributes :body, :author, :email end end { "posts": [ { "comments": [ { "body": "...", "author_name": "Comment Troll", "email": "troll@trolling.edu" } ]} ]} Friday, September 30, 2011
  • 19. OTHER FEATURES Uses multi_json gem -- pick your encoding library Bldr.handler Friday, September 30, 2011
  • 20. Bldr.handler BSON::ObjectId do |value| val.to_s # => "4e77a682364141ecf5000002" end Friday, September 30, 2011
  • 22. MORE INFO github.com/ajsharp/bldr @ajsharp ajsharp@gmail.com zaarly.com / alexjsharp.com Friday, September 30, 2011