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


Talk Python's Mastodon Michael Kennedy's Mastodon