Advertisement
Guest User

API Change notification done right - MongoLab

a guest
Oct 18th, 2011
397
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.34 KB | None | 0 0
  1. Dear MongoLab customer,
  2.  
  3. If you're using our REST API, you need to be aware of an impending change to the way we treat the Content-Type Header that *may* require code changes from existing applications.
  4.  
  5. We are making this change to improve the experience of working with our REST API, specifically by detecting and providing feedback in a very common failure scenario. The change we are making is to require a corresponding Content-Type header (set to "application/json") for any request that takes a body. Previously, we had a more relaxed policy that would try to handle requests regardless of the Content-Type that was set. Unfortunately, this can fail silently and leave the developer in a very confusing situation that can take a while to resolve.
  6.  
  7. What:
  8. * Stricter enforcement of the Content-Type header in MongoLab's REST API; code changes possibly required
  9.  
  10. Applies to:
  11. * MongoLab REST API users that have not set the Content-Type header to "application/json" for existing requests with bodies (most commonly PUT and POST requests)
  12.  
  13. When:
  14. * Saturday October 29 at 11 pm pacific (October 30 at 2 am eastern)
  15.  
  16. Required change:
  17. * Set Content-Type header to "application/json" for any request that takes a body (most commonly PUT and POST requests)
  18. * See below for a jQuery example; many more examples at http://support.mongolab.com/entries/20433053-rest-api-for-mongodb)
  19.  
  20. Details:
  21. * MongoLab's REST API will now require a corresponding Content-Type header (set to "application/json") for any request that takes a body
  22. * Any request without a Content-Type header or with a Content-Type header that is not set to "application/json" will generate a 415 Unsupported Media Type response (http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html)
  23.  
  24. Testing your code:
  25. * If you supply an additional header Content-Type-Enforcement (set to "strict"), you can effectively "turn on" the new behavior and test your code prior to when we make this change
  26. * See example below
  27.  
  28. As always, please don't hesitate to let us know at support@mongolab.com if you have any questions... and thank you for using MongoLab!
  29.  
  30. All the Best,
  31. The MongoLab Team
  32.  
  33. http://mongolab.com
  34. twitter: @mongolab
  35.  
  36. ###########################################################################
  37. # Example of POST request using jQuery
  38. ###########################################################################
  39.  
  40. $.ajax( { url: "https://mongolab.com/api/1/databases/my-db/collections/my-coll?apiKey=1234",
  41. data: JSON.stringify( { "x" : 1 } ),
  42. type: "POST",
  43. contentType: "application/json" } );
  44.  
  45. ###########################################################################
  46. # Test your code prior to the change date using the "Content-Type Enforcement" header
  47. ###########################################################################
  48.  
  49. REQUEST:
  50.  
  51. POST https://mongolab.com/api/1/databases/my-db/collections/my-coll?apiKey=1234 HTTP/1.1
  52. Content-Type-Enforcement: strict
  53. Content-Type: application/x-www-form-urlencoded
  54.  
  55. { "bowTiesAreCool" : true }
  56.  
  57. RESPONSE:
  58.  
  59. HTTP/1.1 415 Unsupported Media Type
  60. Server: Apache-Coyote/1.1
  61. Content-Type: application/json;charset=utf-8
  62. Transfer-Encoding: chunked
  63. Date: Fri, 14 Oct 2011 01:08:07 GMT
  64.  
  65. { "message" : "Unexpected Content-Type 'application/x-www-form-urlencoded', expecting 'application/json'." }
  66.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement