Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting explicit response Content-Type in CouchDB

Tags:

json

couchdb

I'm looking for a way to set the Contet-Type for couchdb response.

I have POST a JSON using Content-Type and Accept request headers as application/json. But when I call the GET for that document, it returns the JSON response with Content-Type text/plain; charset=utf-8. What I'm expecting is getting application/json as it's Content-Type.

How can I do this?

POST

  • URL : http://localhost:5984/hotel_staticdata
  • Request Body : {"_id":"test-hotel-stat-data","content":[{"hotelcode": "AMB3_LON","hotelname": "Ambassadors Bloomsbury"},{"hotelcode": "ALE1_LON","hotelname": "Alexandra"},{"hotelcode": "ALE1_LON","hotelname": "Alexandra"}]}
  • Request Headers : Accept : application/json Content-Type : application/json

GET

  • URL : http://localhost:5984/hotel_staticdata/test-hotel-stat-data
  • Response Body : {"_id":"test-hotel-stat-data","_rev":"3-6c6e26cd5690794886a8dc65308bf078","content":[{"hotelcode":"AMB3_LON","hotelname":"Ambassadors Bloomsbury"},{"hotelcode":"ALE1_LON","hotelname":"Alexandra"},{"hotelcode":"ALE1_LON","hotelname":"Alexandra"}]}
  • Response Headers : Content-Length : 249 Content-Type : text/plain; charset=utf-8

Instead of this, I tried PUT then GET also but the results is same.

  • CouchDB version : 1.6.1
like image 802
namalfernandolk Avatar asked Mar 06 '17 08:03

namalfernandolk


1 Answers

I got the answer.

When I call the GET with Accept:application/json request header. It works! Damn! How did I miss it!

Anyway, If you have any different solution please feel free to post.

like image 87
namalfernandolk Avatar answered Nov 13 '22 11:11

namalfernandolk