RESTful and HTTP APIs in Pyramid Transcripts
Chapter: Customer Renderers
Lecture: Generating both CSV and JSON responses

Login or purchase this course to watch this video and the rest of the course contents.
0:01 So we've seen that we're getting csv back, if we'd run this again, boom, there you go, we have our csv data, we have the status,
0:10 here if you look at the headers you can see the content type is set along with the character set, so we're definitely doing the exchange correctly.
0:16 Now, what if we wanted our json back, here is some stuff, we'll get to that later, so what if we want to say I am going to accept,
0:27 notice over here we can say csv, and we should get the same, maybe we would like to be able to say json as well, send json,
0:37 alright, so we can come over here, let's go back to our api, here, and we can say accept type= text/ csv,
0:56 let's go over here and maybe make that csv, application/ json, so I put json back, run it again, oh sorry that was supposed to be just accept,
1:06 okay, so now, let's try this again, first of all, let's go over here and say csv, we should get the same, now if we put json, now we get json,
1:19 isn't that cool, here, let's do like this, accept csv, so turn this one off, look at that, turn this one on, and we'll go back to json.
1:33 So you can see we have both of these renderers in play in the next chapter what we are going to look at is
1:37 how to make this entirely controlled by the client and have the server have nothing to do with it,
1:43 it will just render whatever it's supposed to render, like whatever they ask for, but, for now, we'll have these two types,
1:49 because I want to still have the json option.


Talk Python's Mastodon Michael Kennedy's Mastodon