--
You received this message because you are subscribed to the Google Groups "sinatrarb" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sinatrarb+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to a topic in the Google Groups "sinatrarb" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/sinatrarb/7_ZsExsAFB8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to sinatrarb+unsubscribe@googlegroups.com.
If you care a lot about efficiency, you might want to try Hobby. According to this benchmark, Hobby is a lot faster than Sinatra.
I am writing an API in sinatra. It will be a pure JSON api so I need to parse the body as JSON and I am wondering whether it's more efficient to do that with a middleware or as a before hook?
Also a question about the general setup. I will have public paths and private paths and I will be using JWT. One approach is to create a namespace for the private and as a before or use setting make sure the JWT exists and is valid. Another approach would be to create two apps one for the private and one for the public and mount them on different paths. Is one way more efficient than the other?
Finally. How about I group similar functionality into a separate app and have many apps each of which inherits from a base app but is mounted on different paths. Does Sinatra initialize all the classes on every request or only initialize them when the mounted path is hit?
I have been working on and off for a couple of weeks on this I must say it's been pretty frustrating. I think I finally got enough plumbing done to try and actually start writing my app now but it took me way longer than I ever thought it would. At this point if I am going to throw away all this work and go someplace else I will either go with rails or maybe even a completely different language like elixir and phoenix or golang or something.Up to this point almost everything I have done has been to try and get a tiny bit of the functionality I get in rails. I am still missing a lot so more work to do yet! Although I appreciate the speed and efficiency of sinatra at this point I would not reccomend these types of micro frameworks for writing anything more than a trivial app. Even then I would say the tooling you get with rails is probably enough to choose it over something smaller and more efficient.Maybe I should have started with padrino. I think that would have saved me a lot of work.
--
BTW the namespace feature of sinatra conflicts with rake namespaces. I found a workaround but just wanted to let you know in case you didn't.
APP_ENV = ENV['APP_ENV'] ||= ENV['RACK_ENV'] ||= ENV['RAILS_ENV'] ||= 'development'
#This is the "real" app root. It will work even when this file is included in specs and elsewhere
APP_ROOT = File.expand_path('../..', __FILE__)
require 'bundler'
Bundler.require :default, APP_ENV.to_sym
#dotenv will not override the actual env vars...
Dotenv.load(File.join(APP_ROOT, '.env.development')) if APP_ENV != 'production'
gem 'sinatra-contrib', require: false
--
My app is the example :)
require 'sinatra'
require 'sinatra/namespace'
p method(:namespace).source_location # => ["/Users/mwp/.rbenv/versions/2.4.2/lib/ruby/gems/2.4.0/gems/sinatra-2.0.0/lib/sinatra/base.rb", 1921]
# I can't do a Rake namespace here!
task(:default) {}
--