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

Talk Python's Mastodon Michael Kennedy's Mastodon