Search code examples
couchdbcouchappcouchrest

How can I replay a header which is sent in request to couch db?


How can I replay a header which is sent as request to couch db, catch is I want to do it for all documents of data base irrespective of show functions.

So I would send a request to couch db for creating a document as

 curl -X POST -i -H "Content-Type: application/json" -H "User-Agent: CURL" --data-binary          @${INPUTFILE}  http://someip:port/db

where db is my database name created already in couch db and input file is json file to be sent to couch db which will be stored.

Here the response is always as follows

HTTP/1.1 201 Created
Server: CouchDB/1.5.0 (Erlang OTP/R16B01)
Location: http://someip:port/db/14f49d6e537268402761d873560b1da9^M
ETag: "1-ad9ad86f3ca9b8671cd0fcb9e546971f"
Date: Mon, 10 Mar 2014 19:41:07 GMT^M
Content-Type: text/plain; charset=utf-8
Content-Length: 95
Cache-Control: must-revalidate^M

{"ok":true,"id":"14f49d6e537268402761d873560b1da9","rev":"1-ad9ad86f3ca9b8671cd0fcb9e546971f"}

Now I need get an additional header in the response. I know we can easily do this by showfunctions, but the catch there is I have to send post request to a url of that show function similar to as follows

http://someip:port/db/_design/mydesigndoc/_show/myshowfunction

But I don't want this, I want to know whether it would be possible to just post to http://someip:port/db/ and get a custom response header back?

Or is there a way where I can front end the address to http://someip:port/db and forward it to http://someip:port/db/_design/mydesigndoc/_show/myshowfunction when ever I receive a request? I guess this should be possible, but couldn't figure out.

Any help would be greatly appreciated. Thanks


Solution

  • Perhaps the virtual hosts and/or rewriting documentation will help:

    http://docs.couchdb.org/en/latest/config/http.html#virtual-hosts