Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Dear MongoLab customer,
- 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.
- 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.
- What:
- * Stricter enforcement of the Content-Type header in MongoLab's REST API; code changes possibly required
- Applies to:
- * 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)
- When:
- * Saturday October 29 at 11 pm pacific (October 30 at 2 am eastern)
- Required change:
- * Set Content-Type header to "application/json" for any request that takes a body (most commonly PUT and POST requests)
- * See below for a jQuery example; many more examples at http://support.mongolab.com/entries/20433053-rest-api-for-mongodb)
- Details:
- * MongoLab's REST API will now require a corresponding Content-Type header (set to "application/json") for any request that takes a body
- * 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)
- Testing your code:
- * 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
- * See example below
- 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!
- All the Best,
- The MongoLab Team
- http://mongolab.com
- twitter: @mongolab
- ###########################################################################
- # Example of POST request using jQuery
- ###########################################################################
- $.ajax( { url: "https://mongolab.com/api/1/databases/my-db/collections/my-coll?apiKey=1234",
- data: JSON.stringify( { "x" : 1 } ),
- type: "POST",
- contentType: "application/json" } );
- ###########################################################################
- # Test your code prior to the change date using the "Content-Type Enforcement" header
- ###########################################################################
- REQUEST:
- POST https://mongolab.com/api/1/databases/my-db/collections/my-coll?apiKey=1234 HTTP/1.1
- Content-Type-Enforcement: strict
- Content-Type: application/x-www-form-urlencoded
- { "bowTiesAreCool" : true }
- RESPONSE:
- HTTP/1.1 415 Unsupported Media Type
- Server: Apache-Coyote/1.1
- Content-Type: application/json;charset=utf-8
- Transfer-Encoding: chunked
- Date: Fri, 14 Oct 2011 01:08:07 GMT
- { "message" : "Unexpected Content-Type 'application/x-www-form-urlencoded', expecting 'application/json'." }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement