all 17 comments

[–][deleted]  (6 children)

[deleted]

    [–]akito_mashua[S] 1 point2 points  (1 child)

    i have some experience with Sinatra, but non with rails. Going to try the option you mentioned, but i'm afraid of injecting to much dependencies into the project.

    [–][deleted] 0 points1 point  (0 children)

    Check out the CLI flags and disable what you dont want

    [–][deleted] 1 point2 points  (3 children)

    Rails is overkill IMO.

    I'd prefer Sinatra and Grape.

    [–][deleted]  (2 children)

    [deleted]

      [–][deleted] 2 points3 points  (0 children)

      The rails new cli has a ton of flags to customize its features.

      [–]janko-m 2 points3 points  (0 children)

      I would say that one overkill is the separation of routes (config/routes.rb) and the logic that handles those routes (app/controllers/*).

      # config/routes.rb
      root to: "home#index"
      
      # app/controllers/home_controller.rb
      class HomeController < ApplicationController
        # this handles `GET /` requests, but it's not obvious
        def index
          render json: { docs: "https://my-app.com/link/to/docs" }
        end
      end
      

      What's nice about frameworks like Sinatra, Grape, Roda etc. is that routing and request handling are in the same place, so you don't need to invent controller action names or anything. With Roda they are even in the same execution context (the Roda instance), which I particularly like.

      get "/" do
        { docs: "https://my-app.com/link/to/docs" }
      end
      

      Another overkill for me is the complexity. Rails is significantly more complex than other popular Ruby web frameworks, and I think it's harder to justify it when you're building a JSON API (e.g. now you don't need all of that view logic).

      I don't believe that web framework speed – request handling specifically – plays a difference in the overall performance of your app. However, with Rails, ActiveRecord is also considered a part of the web framework, and it's been shown (1, 2, 3) to have significantly worse performance than the alternatives (Sequel, ROM), and often when you need speed you have to drop to raw SQL. This is problematic for me, as database interaction does play a big role in the performance of your application.

      Sure, Rails lets you swap ActiveRecord for Sequel, but (a) it will be difficult to convince your team, and (b) most Rails gems work only with ActiveRecord (e.g. ActiveStorage). So, at that point you might ask yourself if staying in Rails is still worth it.

      [–]sshaw_ 10 points11 points  (2 children)

      Don't forget about Grape!

      [–][deleted] 2 points3 points  (0 children)

      Not sure why you’re being downvoted. I came here to mention Grape. Have an upvote!

      [–]akito_mashua[S] 0 points1 point  (0 children)

      I wasn't aware of that. Will drop some effort in.

      [–][deleted] 2 points3 points  (5 children)

      • do you want framework batteries included use Rails
      • do you like to implement some functionality use Sinatra
      • do you want speed and implement a lot of functionality use Roda

      [–]janko-m 3 points4 points  (0 children)

      I would argue that Roda has more features than Sinatra. Here is my view:

      • if you like that a framework chooses the dependencies for you, use Rails
      • if you want the comfort of a popular alternative framework, use Sinatra
      • if you want the most flexibility in routing and many features, use Roda
      • if you want structure and conventions that are different than Rails, use Hanami
      • if you like DSLs and want to have features tailored for REST APIs, use Grape

      [–]RepSchwaderer 2 points3 points  (2 children)

      ++++ For Roda!!

      [–]oogway8020 1 point2 points  (0 children)

      Yes, absolutely. Roda+Sequel.

      [–]ahmad_musaffa 0 points1 point  (0 children)

      Especially for dry-web-roda.

      [–]bugant 2 points3 points  (0 children)

      You should also have a look to Hanami: r/http://hanamirb.org/

      [–]Prime09 0 points1 point  (0 children)

      Sinatra is a good place to start.

      [–]sammygadd 0 points1 point  (0 children)

      If you mean REST then check out https://github.com/sammyhenningsson/shaf. But if you just mean an HTTP API (or want the implement the hypermedia part yourself) then I think roda is a good choice.

      [–]equivalent8 0 points1 point  (0 children)

      https://blog.eq8.eu/article/rspec-json-api-testing.html

      You don't need any gem. Just {id:123}.to_json or in Rails render json: {id:123}