00:00 If we look at our service,
00:01 it tell us the way to create a post
00:04 is to add HTTP POST against that URL.
00:07 And what we need to do in our post,
00:10 is basically pass this information along.
00:13 A title, a content, a view count, and a publisher.
00:16 We don't need the id that's generated by the database.
00:19 We need to somehow do that, and it starts out looking pretty
00:25 obvious, but then it's not so obvious it's easy,
00:27 it's just not obvious.
00:29 So we know that we want to do HTTP POST against
00:34 /api/blog, and this will be create new entry.
00:40 And it's going to have some stuff that goes here.
00:43 This'll be create a new post, but what well it turns out
00:50 right at this level, I don't love the way that this works,
00:54 I would like to see something different, but here's how it
00:57 works. Basically you pass
00:59 **kwargs, you pass arbitrary keyword arguments.
01:02 And then what you say is this an uplink.body
01:06 So this document maps to the body.
01:08 Now this is actually not going to work quite at first,
01:11 it's going to give us the funky error, the fix is super easy
01:15 I want you to see me run into the error,
01:17 so that you can get around it.
01:20 It really depends on what the service is expecting, this
01:23 service expects a JSON body, if this was like a form
01:26 post type of thing, then what we actually have is perfect.
01:29 So let's go and try to use this.
01:33 I'll just pay some code that gets the input from the user.
01:36 Okay so, here's what we're going to do, we're going to ask
01:38 for the title, the body, and the view count from the user
01:42 again no error handling on the view count,
01:44 but you should add that.
01:45 And then we're just going to say it's published right now,
01:47 when you right it.
01:48 You can't change that.
01:49 And so we're going to call create new entry
01:51 and we're going to use keyword arguments here.
01:53 Now PyCharm is being a little more, helpful.
01:57 Basically the way they're using type annotations to
02:00 structure the behavior is conflicting with the actual
02:03 type checking that PyCharm is doing here.
02:06 So I'm not sure PyCharm really has this right, I'm not
02:09 sure who I should blame for this little funkiness here.
02:11 But let's just tell it chill out for a minute, so we can
02:14 suppress that for this statement and it will be okay.
02:16 Now this should fail with a 400 bad response, but it's
02:20 not obvious why.
02:22 Let's go and run that, and now notice there's
02:23 a bunch of these that are starting to pile up.
02:26 Let's close them off, and tell this to run a single instance
02:30 so it restarts.
02:31 Alright let's try this, I'm going try to right a post,
02:34 this is going to be just created this, and the contents are
02:39 going to be a new post, it's viewed 71 times, and boom 400.
02:43 Bad request. Why?
02:46 Well it's not at all obvious why,
02:49 you'd have to somehow look at the response from the server
02:52 or something to that effect maybe the server
02:54 could give you a better answer.
02:56 Could not parse the JSON body you sent,
02:58 it looks like this but I expected something else,
03:00 this service doesn't give us enough
03:02 information really to know.
03:03 But I'll tell you what is happening is,
03:05 it's actually doing form encoded post, rather than a JSON
03:09 post.
03:10 So we need to tell this little client,
03:13 hey when you post stuff to this server do that in JSON form
03:16 not standard web form.
03:17 So we can just say a uplink.json.
03:19 So now this applies to every method anytime it sees the body
03:23 that means JSON when we say that.
03:25 Let's run it again and this should work,
03:27 and let's do a quick read just to see.
03:29 Notice there are 4, let's do one,
03:31 now let's write a new post, this was done live,
03:36 and it should come into existence.
03:38 Should be fun to see it appear now, and it's very popular.
03:43 Boom, look at that it's created.
03:45 Well our program said it's created,
03:47 has an id that means is like probably did,
03:50 but let's just hit list again.
03:51 Look at that, number one this was done live,
03:54 and let's actually view the details of it.
03:56 This was done live, right now you can see
03:59 when it was recorded, and it should be fine
04:00 and appears right now, this is totally cool.
04:02 Let's do one little quick fix, up here let's put a comma.
04:05 Digit grouping in there, so over here
04:10 we can say colon comma, that will do Digit grouping.
04:14 Now we can read them, 1000 view perfect this was done live.
04:19 To review we figured out what the URL
04:23 is that we're going to work with.
04:24 For various API end points, we created functions
04:28 that map that information to behaviors we're doing here.
04:32 And then we just call them, and we don't even implement
04:35 anything, look there's literally no implementation to any of
04:38 these methods.
04:39 They're just documented which is pretty wild actually.
