#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
0:01 API endpoints doing JSON-ie stuff,
0:04 but, well not quite yet, almost,
0:06 but they are sort of set up for RESTful interactions.
0:10 But they don't return any real data, do they?
0:14 So, this one's pretty easy.
0:15 Let's work on this.
0:18 So what we're supposed to return here is a list of names
0:21 that then the client can use to show to the player,
0:25 and say which one do you want to play.
0:27 We could return rich objects,
0:29 but really just the names are enough.
0:32 So we're going to use a list comprehension to
0:33 take the database objects which have all sorts of stuff,
0:36 don't go in JSON very well, and just convert those
0:39 to just the particular names.
0:41 So we'll have r.name for r in game_service.all_rolls.
0:48 And then down here remember,
0:49 we say flask.jsonify(rolls).
0:54 All right, it's still running down here, see the dot?
0:56 So it should've restarted, let's give this
0:57 all rolls here a shot.
1:00 Remember we've said this before,
1:01 what'd give you all the rolls?
1:02 There we go, make that an easier read.
1:05 Boom, look at that.
1:06 So we got this back, here's our JSON.
1:08 We look at the headers we got out of JSON,
1:11 that's it, we've implemented it.
1:13 Let's review.
1:14 We got a list of names, we returned Flask JSON,
1:18 we listed to the right URL, and the right HTTP verb, done.
1:21 All right, well, that was easy,
1:23 let's see another one that's easy.