Created
August 9, 2011 00:25
-
-
Save brikis98/1133133 to your computer and use it in GitHub Desktop.
Ruby/Sinatra examples
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # For a given company id, update the company's location and website | |
| post '/company' do | |
| # ... process the request ... | |
| "id = #{params[:companyId]}, location = #{params[:location]}, website = #{params[:website]}" # echo back the params | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| post '/company' do | |
| # Fetch the current member's profile and group data in parallel from two Frontier Content Services | |
| member, groups = assemble { | |
| GET resource(:profile, :v0), {:memberId => session[:memberId]} | |
| GET resource(:group, :v0), {:memberId => session[:memberId]} | |
| } | |
| # ... Use member and groups data ... | |
| "#{member.firstName} is in #{groups.size()} groups" | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| post '/company' do | |
| # Fetch the current member's profile and group data in parallel from two Frontier Content Services | |
| member, groups = assemble { | |
| GET resource(:profile, :v0), {:memberId => session[:memberId]} | |
| GET resource(:group, :v0), {:memberId => session[:memberId]} | |
| } | |
| # ... Use member and groups data ... | |
| # Now update the company info | |
| company = resource(:company, :v0) | |
| params = {:companyId => params[:companyId], :location => params[:location], :website => params[:website]} | |
| result = assemble { | |
| PUT company, params | |
| } | |
| "#{member.firstName} just updated the company info for company #{params[:companyId]}" | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Matches www.linkedin.com and prints "Hello World" | |
| get '/' do | |
| "Hello World" | |
| end | |
| # Matches URLs that start with /hello/ and pulls out a named parameter at the end, | |
| # e.g. www.linkedin.com/hello/Kevin prints "Hello Kevin" | |
| get '/hello/:name' do |name| | |
| "Hello #{name}!" | |
| end | |
| # Matches URLs with a wildcard between hello and world and extracts query/body params, | |
| # e.g. www.linkedin.com/hello/fooooo/world with a body of {"name": "Jim"} prints "Hello Jim" | |
| post '/hello/*/world' do | |
| "Hello #{params[:name]}" | |
| end |
@efleming
It's not really "proprietary" per se, but it does use a lot of internally developed Java libraries so it would be harder to make sense of. You should check out https://github.com/avik-das/asap to see an open-sourced implementation developed here that does something very similar.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for the info, I was just more interested in what the basics of the assemble method looked like behind the scenes. I understand if that is proprietary information, thanks for the info. This is great and I really enjoyed the article. I am working on a very similar application architecture for an app I work on that is JRuby on the front end (we're using Rails) and a bunch of individual Java services on the back end.