RESTful and HTTP APIs in Pyramid Transcripts
Chapter: Calling services with Python and JavaScript
Lecture: Calling services with Postman

Login or purchase this course to watch this video and the rest of the course contents.
0:01 So we've created a service and we've played with it a little bit with Firefox,
0:04 but let's look at different ways in which we might interact with it.
0:08 Now, this might seem pretty simple, I'll just fire up a request and make a request to it
0:13 but it turns out some of the more popular clients
0:15 are not so simple to use, and we'll get to those.
0:19 So here we are back in our project, and I just notice one thing
0:23 around organization that we want to take care of since it doesn't fit anywhere,
0:26 this test thing, there should really be a test folder
0:29 like we should have many test files and whatnot;
0:31 so, let's go and make a folder called tests, and then let's just move that in there.
0:36 So now we have a nice clean app all broken into various pieces,
0:42 we've got our data, we've got our API, we've got our initialization
0:45 we've got our standard views for basically html functionality and so on.
0:50 Now, if we're going to call this, obviously it has to be running
0:53 so let's fire it up again and grab the url,
0:56 and notice it runs on a particular port,
0:59 that port is controlled right here in the configuration,
1:04 so if you want to change the port, notice it's listing in both on ipv4 and ipv6 local host
1:11 but 6543 if you want to make it listing somewhere else, you can easily change that.
1:15 All right, so right now, we're listing in here
1:17 and we're going to start with one of the simpler
1:20 but really powerful tools for exploring this,
1:22 basically we're going to look at three things:
1:25 we're going to look at using a gui API testing exploration tool,
1:29 we're going to use Python and this could be Python from a client application
1:35 or this could be Python from one web app,
1:37 consuming another service somewhere else,
1:40 it could be your own service, it could be other services,
1:42 you could be having your service, consume other services
1:44 to do its functionality, things like that;
1:46 so we're going to use requests and Python there and finally
1:49 we're going to look at javascript and interacting with it via javascript.
1:53 So let's start with postman, so postman you can get this at
1:59 I think it's .com, definitely getpostman,
2:01 you can use this to explore and record and test APIs,
2:05 notice I've got some say for various APIs I'm working with over here.
2:09 You downloaded it, it runs cross-platform, it's an electron js app, it's really nice.
2:15 So we come over here and we can enter this url and we can do a get,
2:19 and notice, it just loads up whatever we got,
2:22 and it's going to load up this, right, so what we really want to do
2:25 remember is we want to go to /api/autos, let's do a send there,
2:30 we get all this data back, and it even gives you the timing here, which is pretty cool,
2:34 the very first time it has to parse those twenty thousand files
2:38 out of that csv so it's little slow, 700 miliseconds kind of slow,
2:42 but if we hit it again, 16 milliseconds, 15 milliseconds and so on.
2:46 Now, this is not a great view,
2:49 so we can see the raw view, we can see the pretty view
2:51 it knows that it's json, so it gives us lots of things.
2:54 We can look it over at the header, what's the server what's the format
2:57 what's the content length, we can even create some tests
3:00 but that's sort of outside the scope here.
3:03 So there's something funky going on with that json, isn't there;
3:09 let's have a quick look, I mean notice like, point appears
3:12 like oh yeah there's definitely there's a weird like a thing here
3:15 and then this, let's see why that's happening actually.
3:24 So we have all of our cars here, I think it might be because of this,
3:32 I think we don't want items, we want values, that's definitely it.
3:37 Ok, so let's do it again. That looks more appropriate,
3:41 it was sending the key value, ok so we've got this
3:44 and that was already pretty nice to actually explore this way,
3:47 and obviously we could do this in Firefox, that was no problem
3:52 but I could come over here and I could set up the parameterization,
3:57 I could set up authorization, I could go over here
4:00 and what do get if we do a post here-
4:03 right, and if we're going to do a post,
4:05 well we need to set the body, right things like that.
4:09 So if we do a post, notice we're getting a 404 not found,
4:12 remember, we're only listening to the get request
4:14 things like that, so let's go back to get.
4:16 So it lets us explore all of these things around this,
4:19 and then we can save it so I could go over here hit save, create a little collection,
4:23 notice on the left there is a different little collections,
4:25 and those actually sync back to my account at postman.
4:28 So, we will probably be coming back to this, to play with it
4:31 when we get to post, and other interesting things, okay,
4:36 but for now, here is the body we could go and change,
4:40 we can go and actually enter the body is like raw stuff here
4:46 and we could just type in the json that we want to post up to them, ok
4:50 so it lets us control all the things we need around post and headers, and so on.
4:54 If you're building serious APIs, you definitely want to take the time
4:59 to download postmen, there's a couple of other apps that are like it,
5:02 but I found postman to be pretty solid and enjoyed working with it,
5:06 and basically there's a free version so it's worth everything you pay for it.