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