Your SlideShare is downloading. ×
Bldr: A Minimalist JSON Templating DSL
Bldr: A Minimalist JSON Templating DSL
Bldr: A Minimalist JSON Templating DSL
Bldr: A Minimalist JSON Templating DSL
Bldr: A Minimalist JSON Templating DSL
Bldr: A Minimalist JSON Templating DSL
Bldr: A Minimalist JSON Templating DSL
Bldr: A Minimalist JSON Templating DSL
Bldr: A Minimalist JSON Templating DSL
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Bldr: A Minimalist JSON Templating DSL

744

Published on

Lightning talk from Railsconf 2013. …

Lightning talk from Railsconf 2013.

https://github.com/ajsharp/bldr

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
744
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
2
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. BldrA minimalist JSON templating DSLgithub.com/ajsharp/bldr
  • 2. github.com/ajsharp/bldrgithub.com/ajsharp/bldr
  • 3. github.com/ajsharp/bldrWhat?• Produce JSON from ruby objects• 4 core API methods• Treat json API responses as a view layer concern• Support for rack/sinatra and rails 3.2• In production use at Zaarly for ~2 yearsBldr in a nutshell
  • 4. github.com/ajsharp/bldrWhy?• Rails is a great framework for building API services• But #as_json is not for serving prod-ready json• APIs are not intuitive for other json templating engines• See: rabl, json_builder, et al
  • 5. object :post => @post doattributes :title, :bodyend{"post":{"title":"my title","body": "..."}}bldr JSONgithub.com/ajsharp/bldrExample: objects
  • 6. bldr JSONcollection :posts => @posts do |post|attributes :title, :bodyattribute(:created_at) {post.created_at.iso8601}end{"posts": [{"title": "Railsconf 2013 wrap-up","body": "...","created_at": "2013-05-01T14:18:16-07:00"},{"title": "OMG Railsconf is coming up!","body": "...","created_at": "2013-04-20T08:01:12-07:00"}]}github.com/ajsharp/bldrExample: collections
  • 7. bldr JSONcollection :posts => @posts do |post|attributes :title, :bodyattribute(:created_at) { post.created_at.iso8601 }collection :comments => post.comments do |comment|attributes(:author_name)attribute(:body) {HTML::Whitelister.clean(comment.body)}endend{"posts": [{"title": "Railsconf 2013 wrap-up","body": "...","created_at": "2013-05-01T14:18:16-07:00","comments":[{"author_name": "Bob Bobberson","body": "ohai!"}]}]}github.com/ajsharp/bldrExample: nested collections
  • 8. Rails Sinatragithub.com/ajsharp/bldrclass PostsController < ApplicationController# GET /postsdef index@posts = Post.all.limit(10)render :indexendend# app/views/posts/index.json.bldrcollection :posts => @posts do |post|# ...endclass Api::Posts < Sinatra::Applicationregister Sinatra::Bldrget /posts do@posts = Post.all.limit(10)bldr :posts/indexendend# views/posts/index.json.bldrcollection :posts => @posts do |post|# ...endExample: Rails / Sinatra
  • 9. twitter @ajsharpweb alexjsharp.comgithub.com/ajsharp/bldr

×