Eve: Building RESTful APIs with MongoDB and Flask Transcripts
Chapter: What is Eve?
Lecture: Exploring Eve: Getting Started

Login or purchase this course to watch this video and the rest of the course contents.
0:00 If you go to the Eve homepage, at python-eve.org,
0:04 you'll find that there's a live demo available for you
0:07 to play and experiment with.
0:09 The source code for this demo is on github,
0:12 so any time you can go and check it out.
0:14 I suggest you do that once we've done with this course
0:17 you can use this basic app as a reference or a starting point
0:22 to build your first experimental or advanced REST service.
0:26 Thousands of people have been playing and experimenting with it
0:30 to better assess Eve features and functionalities.
0:33 Let's do the same so we can get a gentle introduction to the framework
0:36 and make ourselves a solid idea of what's coming with the rest of the course.
0:40 Now, depending on the browser you are using
0:42 when you click on this link at the Eve homepage
0:45 you will get a different result.
0:47 I remember getting some xml back from Chrome for example,
0:49 here I am on Safari and if I click on this link
0:52 what I get back is basically what appears to be just random strings.
0:56 They are not really random, actually the API is working well
1:00 it's providing us with a nice response
1:02 and if we look at the address bar,
1:04 we already get some nice information
1:06 we are hitting a secured service,
1:08 this service is hosted on Heroku and if I click on that,
1:14 I can see that I'm actually hitting the people endpoint.
1:16 Now, if we want to better assess what's going on
1:20 and understand what the response is
1:23 we really need to switch it to a better client
1:26 browsers are not really the best option
1:28 when you want to use and consume our RESTful service.
1:31 What we really need is a REST client
1:34 and as you might remember,
1:36 we already installed Postman in a previous section of this course,
1:39 so let's just launch it, and here it is
1:43 so on Postman we have two panes,
1:46 on the left side we have the request pane
1:48 and on the right side we have the response pane,
1:51 we enter the URL here, let's just pass
1:55 the same URL we hit before with the browser
1:57 and click the send button.
2:01 After a few seconds, we get response back
2:03 and as you can see, this is actually readable
2:06 and if we check on the headers tab here
2:09 we see that the content type is application Json
2:12 and that the server is actually an Eve instance.
2:15 Now, this service only exposes 2 endpoints
2:19 one is people the other one is works, here it is.
2:25 Now, for both requests we got an OK status back
2:29 because the endpoints were existing
2:31 what if we type an endpoint which doesn't exist?
2:35 Well, of course, as you might expect
2:38 we get a not found back from the framework
2:40 and if we look at the response body,
2:44 we see that actually some Json is provided back
2:47 it has two nodes, error which has details about the error,
2:51 so the error code and the message,
2:53 which is a human readable explanation of the problem, and a status.
2:57 So every time there is an error with a request
3:00 you get a proper status and also a human readable parsable Json
3:06 back from the framework, let's go back to our people endpoint now.
3:12 Of course, you can define as many endpoints as you want on your service
3:17 but what if your client can't process Json and needs xml instead.
3:22 Well, that's easy because it supports both formats,
3:26 all you have to do is perform a slightly different request
3:30 let's go here to the headers tab and say
3:33 that this time we only accept xml and hit send,
3:38 as you can see now, we're getting xml,
3:42 if we go to the response headers tab,
3:44 we see that actually we are provided with xml.
3:47 Let's try again, and switch back to Json, here it is.
3:55 Do know that you can configure your service
3:58 and decide which formats are supported and which aren't.
4:03 By default, your service will support both Json and xml
4:07 but we will see in the following segments
4:09 that we can switch one of them on and off as we please.
4:14 Let's consider the Json response for a moment.
4:17 There are 3 main notes, links, items and meta.
4:21 Meta is easy, we get the total number of documents matching the query,
4:25 the page we run and the maximum number of documents
4:29 we get for every page.
4:31 These settings are of course configurable
4:34 as well as weather pagination is supported or not.
4:38 Link has some navigational information for the client
4:42 and items is an array where we get the actual documents,
4:47 we already know that we should have seven documents in this array
4:53 1, 2, 3, 4, 5, 6, 7, let's pick one, like this one,
5:00 again, every single document has a links node,
5:04 with navigational information.
5:07 And then, there are some meta fields and you can tell these are
5:10 meta fields because they are preceded by these underscore here,
5:13 so here are the unique id for the document,
5:16 the last time it was updated and etag
5:19 which is basically a hash of the document
5:22 and the date the document was created the first time.
5:26 The rest are actual document fields like last name, first name, location
5:31 which, as you can tell, is a subdocument; a role is an array
5:36 so here we have Mark Green living in New York,
5:40 and he is both an author and a copy,
5:44 and he was born on February, 1985.
5:47 Now we are looking at the default response,
5:50 but many features can be disabled
5:52 for example, if you don't like providing the clients with the links,
5:55 know that you can disable them,
5:57 what you can't avoid are the document meta fields like id,
6:01 updated, etag and created, these are needed by the API
6:04 you don't need to mess with them,
6:08 the API will handle them for you and for the clients.
6:11 And they are important
6:12 because they allow the client to perform conditional queries
6:15 and the server can perform optimized queries on the database.