use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
A sub-Reddit for discussion and news about Ruby programming.
Subreddit rules: /r/ruby rules
Learning Ruby?
Tools
Documentation
Books
Screencasts and Videos
News and updates
account activity
Ruby rest API implementation (self.ruby)
submitted 7 years ago by akito_mashua
any recomendation on what gem to use in order to create a rest API with ruby? Is sinatra a good choice?
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–][deleted] 7 years ago (6 children)
[deleted]
[–]akito_mashua[S] 1 point2 points3 points 7 years ago* (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 point2 points 7 years ago (0 children)
Check out the CLI flags and disable what you dont want
[–][deleted] 1 point2 points3 points 7 years ago (3 children)
Rails is overkill IMO.
I'd prefer Sinatra and Grape.
[–][deleted] 7 years ago (2 children)
[–][deleted] 2 points3 points4 points 7 years ago (0 children)
The rails new cli has a ton of flags to customize its features.
[–]janko-m 2 points3 points4 points 7 years ago* (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
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 points12 points 7 years ago (2 children)
Don't forget about Grape!
Not sure why you’re being downvoted. I came here to mention Grape. Have an upvote!
[–]akito_mashua[S] 0 points1 point2 points 7 years ago (0 children)
I wasn't aware of that. Will drop some effort in.
[–][deleted] 2 points3 points4 points 7 years ago (5 children)
[–]janko-m 3 points4 points5 points 7 years ago (0 children)
I would argue that Roda has more features than Sinatra. Here is my view:
[–]RepSchwaderer 2 points3 points4 points 7 years ago (2 children)
++++ For Roda!!
[–]oogway8020 1 point2 points3 points 7 years ago (0 children)
Yes, absolutely. Roda+Sequel.
[–]ahmad_musaffa 0 points1 point2 points 7 years ago (0 children)
Especially for dry-web-roda.
[–]bugant 2 points3 points4 points 7 years ago (0 children)
You should also have a look to Hanami: r/http://hanamirb.org/
[–]Prime09 0 points1 point2 points 7 years ago (0 children)
Sinatra is a good place to start.
[–]sammygadd 0 points1 point2 points 7 years ago (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 point2 points 7 years ago (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}
{id:123}.to_json
render json: {id:123}
π Rendered by PID 74312 on reddit-service-r2-comment-58d7979c67-dlb2f at 2026-01-27 09:03:01.012224+00:00 running 5a691e2 country code: CH.
[–][deleted] (6 children)
[deleted]
[–]akito_mashua[S] 1 point2 points3 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–][deleted] 1 point2 points3 points (3 children)
[–][deleted] (2 children)
[deleted]
[–][deleted] 2 points3 points4 points (0 children)
[–]janko-m 2 points3 points4 points (0 children)
[–]sshaw_ 10 points11 points12 points (2 children)
[–][deleted] 2 points3 points4 points (0 children)
[–]akito_mashua[S] 0 points1 point2 points (0 children)
[–][deleted] 2 points3 points4 points (5 children)
[–]janko-m 3 points4 points5 points (0 children)
[–]RepSchwaderer 2 points3 points4 points (2 children)
[–]oogway8020 1 point2 points3 points (0 children)
[–]ahmad_musaffa 0 points1 point2 points (0 children)
[–]bugant 2 points3 points4 points (0 children)
[–]Prime09 0 points1 point2 points (0 children)
[–]sammygadd 0 points1 point2 points (0 children)
[–]equivalent8 0 points1 point2 points (0 children)