Anvil: Web Apps with Nothing but Python Transcripts
Chapter: Consuming the API with Fitnessd Local app
Lecture: Saving a measurement with the app

Login or purchase this course to watch this video and the rest of the course contents.
0:00 All right, the last thing we need to do is save the measurement. We have the API key, we just need to take that data and send it along.
0:08 Let's actually do a little test here. It resolved, so we'll let this return some kind of thing here. Alright, so we're passing this in.
0:16 We also need to have probably, we have the API key I think we also need to pass the email as well. The server's going to expect that
0:26 so we're going to have to pass it. Let's make that happen up here. Not the cleanest look there, but that's okay.
0:39 I'm going to say return true for the minute but let's figure this out. Okay, so instead of saying this is what we would send
0:43 to the server, let's actually do this. Now, back to postman and we're going to say the URL is base_url plus and let's figure out what we're doing.
0:52 You're in add_measurement. That's what this is. And the data is going to be what we're putting here, like this.
1:05 So we have our API key is going to be API key. We have our email here. And then we have this stuff, it's already kind of good
1:18 so say data.extend or update rather. Off, how about that? So this will add these two keys, or these two things
1:29 into our data and I believe our data's already correct. We're going to find out in a minute. And then, just like before, what did we do?
1:36 We went up here and we went to request data for this one. Actually, yep that should be fine. If the status code's not 200 we're going to return false.
1:51 Otherwise, we're going to return true. And a better way to say that is just return the status code as 200. So let's print out actually server response
2:01 is resp., just put out the text. That will also be the JSON but we'll just see that. Okay, so do it, let's give it a shot.
2:10 Go ahead and run it one more time, do that again. Now it's going to ask for a measurement. The resting heart rate is, let's say one
2:17 not 170, we'll be hurting. Let's say 73 here and then 175. Hit enter, it's going to go to the server. Let's see what happens. Yes! Success is true!
2:31 Let's go see if we have a 73 and 175 over in our app tables. It should be right near the top. Perfect, there our 175 and 73 is at the top.
2:42 Beautiful! It's working, right? So our little API, let's run just one more time. Obviously, the dates are going to be piling up
2:49 on the same day. But let's do 74 and 181. I was beasting during lunch or something. We're going to hit refresh. 181 and 74.
3:04 Check that out, we're using our API former external application. Now, yeah this is a Python application also
3:10 because, hey, I like to write applications in Python and you probably do as well. However, this could be a Javascript app. This could be a Xamarin app.
3:19 It could be C#, it could be Java, whatever. It doesn't matter, that's what APIs are about. We're talking to the API and we're saving our data there.
3:28 How cool is that?


Talk Python's Mastodon Michael Kennedy's Mastodon