Eve: Building RESTful APIs with MongoDB and Flask Transcripts
Chapter: Consuming the service
Lecture: Postman

Login or purchase this course to watch this video and the rest of the course contents.
0:00 Consuming a Rest service is normally done with some kind of client app. This might be a website using Javascript or a stand-alone app usually written
0:12 in some kind of high-level language, such as Python. Another way to consume a Rest service is by using a dedicated Rest client.
0:21 These are used during development of a service or while experimenting and playing around with some third party service just to get a hold of it.
0:31 One very popular Rest client is Postman and we're already familiar with it. We'll only spend a few minutes looking at its main features
0:41 so you can leverage them as you're developing and testing your very own Rest service. I also want to take this opportunity to mention
0:50 how you should not be using a dedicated Rest client. More on that at the end of this lecture, We already know how to pick a request method
1:00 and how to enter a endpoint URL so for example, here we want to hit local host 5000 we've been doing this for a while,
1:14 a nice feature is the history, we can click on this button here and it will show us a history off all the requests we sent to the service.
1:24 This is very nice, especially when you are working with complex requests you don't have to retype them every single time
1:32 insert the headers again, the body of the request etc, in this case, I'm calling back a request to our if demo on Heroku
1:42 and as you can see here, we have a query, we're asking for page one. Another nice feature is the parameters form.
1:50 Here you can insert your parameters filling up this form instead of going here and manually insert all your requests,
1:59 for example, let's say that we want page one and max result,. which, by the way, is an option we haven't seen yet.
2:07 Here, we're asking for the first page, or let's try with second page and every page must be of 10 records or documents,
2:17 as you can see, as I type here, the URL is being updated for me. So less error prone and probably nice if you're doing complex requests.
2:28 Let's go back to our history and recall a post request like this one here we want to play with the headers and body tabs.
2:37 We already know that when we're working on the body of the request we can pick the raw format and we have several options here
2:45 usually when working with a Rest service, we want to work with Json, if you need different formats for example xml, or text
2:54 you can just take whatever you need here, and when you pick a format. usually Postman is smart enough to select the correct header for you
3:03 as we saw already, the content type is already set for us. You might also switch to a bulk editor here you basically get a text editor,
3:13 you can write whatever you want here without any form of validation. Another powerful for feature we'll be using in a little while is
3:20 support for authorizations schemes. So we can go here and pick one of the many supported authorization and authentication schemas,
3:31 for a example basic auth which is very common, insert our user name and password and then every time we click the send button an authorization header
3:40 will be added for us, we can preview the request, if we click this button, we go back to the headers
3:46 we see that an authorization header has been added for us and it is already encoded, very nice.
3:50 Now the history option is very nice, but what's even better, we can save our requests, when you hit the save button, a form pops up
4:02 and we can insert a request name and optional description, and what's even better is we can create collections.
4:09 So, for example, let's create a collection for our Eve course, we will be saving our requests here and when we hit save,
4:19 as you can see, we have two tabs here, history and collections. And our Eve course collection only has one request right now.
4:27 When I click here, it will fill my request form. There are two more features I want to mention, and they are the tests and the prerequisite snippets.
4:37 Now the idea here for both of them is that you can write some Javascript code before the request is sent
4:44 or after the response had come back from the server, for example, here we have the snippet where we're testing that
4:51 this string is included with the response text, so yes, this is a test, but really I don't believe this is a good idea.
4:59 Tests should be sitting alongside your server code you want your test to be there, both Flask and Eve come with great support for unit testing.
5:09 and if you keep your test with your server code you're guaranteed that wherever your code moves, your unit tests will follow, which is super important.
5:19 Also, this will allow you to eventually enable continuous integration, which is super important. So please do your tests, write your tests
5:29 and keep them with your server code, don't use an external third party Rest client to test your server.

Talk Python's Mastodon Michael Kennedy's Mastodon