#100DaysOfCode in Python Transcripts
Chapter: Days 97-99: Building JSON APIs
Lecture: What API operations are required?

Login or purchase this course to watch this video and the rest of the course contents.
0:00 Now before we write some code and we're going to do some pretty interesting things, I think, in terms of organization and the way
0:06 we put this all together but let's just think at a really high level, what operations does our website need to support?
0:13 So we'll talk about how to build these. But let's just sit back and think about, if you can remember back to our 15-way persistent
0:21 Rock Paper Scissors, pretty recent, we had a couple of things that were happening in that game. Here's what I think we're going to need to do in order
0:30 to move all the logic and persistence to the server and still let the client communicate with it. So first of all, you're going to need to be able to
0:38 register a user or get an existing user and I broke those apart you know, with a website, it just kind of seemed like you should either
0:45 kind of login or register as two separate things. You can put them separate or if you want to,
0:50 you can combine them back like we had get or create user. We want to start a new game, now this is really important
0:56 because what we're going to do is we're going to create basically an id for the game and all subsequent
1:01 operations will exchange that game id as part of who they are and how they're interacting so if you ask
1:08 for, show me the history, who won, play a round, you're going to pass around this id that we get by starting a new game,
1:14 we will show the rolls and let the user pick the rolls from an existing list. Now we could just hard code the 15 rolls into the client
1:22 but what if we want to someday upgrade it? Maybe around St. Paddy's Day, you could throw a leprechaun and you want to make that a feature of the game,
1:29 you want to add it, it just automatically have everybody pick those up or you want to convert it to 25-way
1:34 Rock Paper Scissors or something along those lines. So we're going to get the rolls from the server so that we're always consistent
1:40 with what the server expects. We can ask, what is the game status? Most importantly, is it over and who won and things
1:47 like that but this will kind of give us the history and the status of whether it's over and so on and finally one of the critical parts
1:55 is actually playing a round. I want to roll the devil and see what happens, right. We'll have a computer player on the other side
2:02 and they'll randomly choose something and you'll see if they win, whether you win and so on. But this is sort of the playing of the game
2:09 and we'll just play the rounds until we find out that the game is over. And finally, one of the fun things we had in the original
2:15 game, the persistent one, was when it started it showed that the players with the top scores. Of course, those were just the players on your machine
2:23 that you happened to have played previously. We're going to add a top scores operation so basically you get the global top scores and you can be ranked
2:32 in the top ten, in the entire world in 15way Rock Paper Scissors demo app, wouldn't that be cool?
2:38 So you'll be able to see that here, as it comes along. So these are the operations we're going to build in Flask.


Talk Python's Mastodon Michael Kennedy's Mastodon