Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a REST API for a Ruby application?

Tags:

rest

ruby

I would like to know how to provide a Ruby application with a REST API. I could code something based on Ruby's TCPServer API, but that seems a bit low-level. Do you think it would be a good solution? Or do you recommend a better approach?

like image 981
StackedCrooked Avatar asked Nov 02 '09 10:11

StackedCrooked


People also ask

What is RESTful API in Ruby on Rails?

A REST API uses RESTful routing just like the routing we've already used in our Rails applications. It's also stateless, which means our API application and the applications our API communicates with don't need to know about each other's state.


2 Answers

For simple REST APIs I would also consider working directly against the Rack library (i.e. you may not need a framework like Sinatra). Routing for example can be quite easy for simple cases. I've put together a little example here: https://gist.github.com/4685445

like image 59
Peter Marklund Avatar answered Sep 28 '22 07:09

Peter Marklund


You can use Sinatra to write tiny, focused web applications and lightweight REST services very quickly.

In the documentation section they highlight a couple of videos on that matter:

  • Adam Wiggins and Blake Mizerany present Sinatra and RestClient at RubyConf 2008. The talk details Sinatra’s underlying philosophy and reflects on using Sinatra to build real world applications.

  • Adam Keys and The Pragmatic Programmers have started a series of screencasts on Sinatra. The first two episodes cover creating a tiny web app and creating a REST service. $5 a pop.

You can also use rails as well, but that's a little overkill...

like image 22
Filipe Miguel Fonseca Avatar answered Sep 28 '22 08:09

Filipe Miguel Fonseca