#100DaysOfCode in Python Transcripts
Chapter: Days 97-99: Building JSON APIs
Lecture: Implementing the all-rolls method

Login or purchase this course to watch this video and the rest of the course contents.
0:00 It is cool that we have all of our API endpoints doing JSON-ie stuff, but, well not quite yet, almost,
0:07 but they are sort of set up for RESTful interactions. But they don't return any real data, do they? So, this one's pretty easy. Let's work on this.
0:19 So what we're supposed to return here is a list of names that then the client can use to show to the player, and say which one do you want to play.
0:28 We could return rich objects, but really just the names are enough. So we're going to use a list comprehension to
0:34 take the database objects which have all sorts of stuff, don't go in JSON very well, and just convert those to just the particular names.
0:42 So we'll have r.name for r in game_service.all_rolls. And then down here remember, we say flask.jsonify(rolls).
0:55 All right, it's still running down here, see the dot? So it should've restarted, let's give this all rolls here a shot.
1:01 Remember we've said this before, what'd give you all the rolls? There we go, make that an easier read. Boom, look at that.
1:07 So we got this back, here's our JSON. We look at the headers we got out of JSON, that's it, we've implemented it. Let's review.
1:15 We got a list of names, we returned Flask JSON, we listed to the right URL, and the right HTTP verb, done. All right, well, that was easy,
1:24 let's see another one that's easy.

Talk Python's Mastodon Michael Kennedy's Mastodon