Eve: Building RESTful APIs with MongoDB and Flask Transcripts
Chapter: Your first Eve service
Lecture: Defining document schemas

Login or purchase this course to watch this video and the rest of the course contents.
0:00 We want to define a schema against which every single document
0:03 coming into our people endpoint will be validated.
0:06 So let's go back to our code editor.
0:11 In Eve, schemas are Python dictionaries.
0:15 Every key in the dictionary is actually a field name
0:22 and the values are dictionaries themselves.
0:26 Let's define the type of this field.
0:29 I did a string and let's also add last name field,
0:34 again of type string.
0:40 Now that we have a definition for our endpoint
0:42 let's add it to our people endpoint configuration.
0:48 The schema is this one.
0:53 So we're telling Eve that our domain is composed
0:57 of just one people endpoint and the schema for the endpoint
1:02 is this one, we have two fields,
1:04 first name, last name, both of type string.
1:07 So every document coming into our API at the people endpoint,
1:11 will be validated against this schema.
1:15 We need to save our file and relaunch the app.
1:22 Now let's go back to our client and try to store our John here.
1:28 And here we go, the status is created,
1:33 and we get a number of metafield back,
1:35 so the data it was created and updated,
1:38 which are, off course, the same, the etag for the document,
1:42 the unique id, the link to the document itself, and the status, which is ok.
1:47 So now that the document has been created,
1:50 we can try and go back and perform our send request to the people endpoint
1:56 and what we get back is an array
1:58 with one document inside it, the meta node,
2:02 as you can see, we have page one and one document total.
2:07 So let's open our document and we see that it is indeed our John, as expected.
2:13 Success!