incubator-couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Filippo Fadda <filippo.fa...@programmazione.it>
Subject Re: A Simple REST API
Date Tue, 12 Nov 2013 02:03:52 GMT
You need to implement a full HTTP/1.1 client with chunk response support, etc. Not so easy,
especially if you don't have a deep background. At least use a gem that implements the http
client or use cURL.

-Filippo

On Nov 12, 2013, at 2:40 AM, S├ębastien Durand wrote:

> Hi !
> 
> I want to use CouchDB for a Ruby project. I downloaded CouchRest, but this
> driver seems to be overkill for what I want : a simple REST API.
> 
> So, is it wrong to design my own driver (using tcp sockets) ? Like this :
> 
> 
> class CouchDB
> 
>  def initialize(database, host = 'localhost', port = 5984)
>    @database, @host, @port = database, host, port
>  end
> 
>  def get(uri)
>    if block_given?
>      yield get(uri)
>    else
>      socket = TCPSocket.open(@host, @port)
>      request = ""
>      request << "GET /#{@database}/#{uri} HTTP/1.0\r\n"
>      request << "\r\n"
>      socket.write(request)
>      response = socket.read
>      socket.close
>      # TODO : parsing json
>    end
>  end
> 
> end
> 
> 
> It's just a dead simple draft, it works, but what are the drawbacks ? Do I
> put myself in trouble ? (I don't have a deep tcp/http background and I fear
> it's not that simple.)
> 
> Thank U for you help !
> 
> S├ębastien


Mime
View raw message