Eve: Building RESTful APIs with MongoDB and Flask Transcripts
Chapter: Fine-tuning your REST service
Lecture: JSON and XML rendering
0:00 We already know that Eve responses
0:02 are automatically rendered as Json or xml
0:06 depending on the request accept header.
0:09 With Json being the default
0:11 eventually you might decide to disable the support for one of the two renderers.
0:18 You simply go to the settings file and set either xml or Json to false,
0:25 they are both true by default, you can't of course switch both of them off
0:32 otherwise your API won't be able to return any value to the clients.
0:37 Also remember that in any case inbound documents
0:41 are always going to be Json
0:43 even if you've disabled Json rendering in your responses.
0:49 Speaking of Json, you might not know
0:51 that the Json format is not ordered,
0:54 which means that every time you send the same request to the server
0:58 you might get of course the same keys but in different orders every single time,
1:03 if you don't like this behavior, you can actually fix that
1:07 by setting the Json sort key option to true,
1:13 if you do this— let me turn Json on again,
1:21 if you set the Json sort keys to true,
1:23 whenever you send a request,
1:28 you are always going to get back keys in the same order.
1:35 Another fairly frequent feature request is
1:38 support for custom accept headers
1:41 or I should say for custom Json formats.
1:45 So what people want to do is still use the accept header
1:50 and then set some custom value like csp-report,
1:56 which is a still a valid Json, it has just a different name.
2:01 You can do that easily in Eve,
2:03 you just set the Json request content types list
2:07 and update it to also support your custom format.
2:12 The default is of course just this value here,
2:16 but you can again extend it to support
2:20 whatever Json your legacy clients are supporting.