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