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

Login or purchase this course to watch this video and the rest of the course contents.
0:00 How's our create game operation working,
0:02 here we're going to do a post of this.
0:04 This says we would create a new game.
0:07 If you think about how the way that
0:09 our data base actually works,
0:11 there's not actually a lot of integrity
0:12 around this game concept and
0:14 we maybe could create some more models
0:16 and put them in there but one of my goals of this
0:18 is to change as little as possible
0:20 about the models and data access layer
0:22 and the other stuff we've already done
0:24 and just to adapt it to online.
0:26 Not exactly possible but it is very, very close.
0:29 What we really need to do here
0:30 is to just create a unique id that can be shared.
0:35 Okay? And it turns out we can do that super easily.
0:43 So we're going to create a dictionary.
0:44 In our dictionary we're going to have a game id
0:46 and how do we get it it?
0:47 It's going to be a UUID,
0:49 which is a standard library thing
0:50 we got to import at the top
0:52 and there's UUID4,
0:53 which is a great random thing we could use
0:56 but we're just going to create
0:57 a string representation of it
0:59 and give that back.
1:00 Let's save this,
1:01 it should reload if everything worked out.
1:03 Instead of saying "would create a game"
1:04 what do we get?
1:06 Boom. There is a very unique looking game id
1:09 that we can then use for all subsequent requests
1:11 to correlate or relate the various operations
1:14 between say playing around,
1:16 getting the game status,
1:17 things like that.
1:18 So that's it.
1:19 Create a game,
1:20 just create a random identifier that we can use
1:22 that is pretty unique.