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