Eve: Building RESTful APIs with MongoDB and Flask Transcripts
Chapter: Your first Eve service
Lecture: Recap

Login or purchase this course to watch this video and the rest of the course contents.
0:01 All right, we have our first Eve application up and running let's review what we've done so far. Our app is made of two Python scripts,
0:10 one is app and the other one is settings. What is perhaps more interesting is that the actual app is 00:16.96 only made of one line of actual code,
0:20 and the second script is more a configuration file than a real Python scrape, and this is probably the basic concept behind any Eve application.
0:30 which is that most of the heavy-lifting is done by the framework itself you mostly have to just configure how it should behave
0:38 according to your use case. On the first line, we're connecting to our db, in this case, we're connecting to a local instance,
0:49 but it could very well be some remote instance, maybe a replica set hosted on, I don't know, Mongo address service or whatever have you.
0:58 Next, we set the methods allowed at both the collection and document endpoint by default, Eve is read only, so if you want to allow for clients
1:12 to write or edit or delete, you have to explicitly say so by extending these lists here. Next, we defined the API surface or as they call it,
1:26 the domain of our API, here we defined one single endpoint, the schema for this endpoint, is defined in people schema over here.
1:38 We only have two fields and they're both of type string, by the way, here we are justifying the type of the field
1:45 but in fact, there are a lot more options we will have a specific lecture about data validation and we will see how many options we have
1:56 when we want to make sure that the data coming in is a properly formatted and validated. Now, you might be wondering
2:04 what if I want some endpoints to be read only, others may be to be write only, and all the rest be read and write?
2:12 We only set the globals here but we can go and overwrite the globals when we define every single endpoint,
2:20 for example, let's say that we have a second endpoint works and here we want to be read only, well, all we have to do is overwrite the global setting
2:30 resource, methods, and then probably we also want to be with read only at the item endpoint
2:45 and that's it, by the way notice how here we're using the lower cases while in the global settings, we use the upper case.
2:53 So, people is going to use the global setting because it is not redefining the rules, works is going to be read only
3:02 because of these two declarations here overwriting the global. Okay, I believe we're done with the first app,
3:10 just keep in mind that because most of the heavy lifting is done by the framework, and yes, it is a strongly opinionated framework,
3:17 most of the features we saw in the quick tour a few lectures ago, they're already available to your app, even if it is a simple one like this one.
3:27 For example, we could go back to our postman client and perform queries sorting, ask for xml rendering— let's do that, just for fun.
3:37 Let's, go here, do a get to our document endpoint and lets ask for xml. Here we go.


Talk Python's Mastodon Michael Kennedy's Mastodon