1 00:00:00,000 --> 00:00:03,594 [MUSIC] 2 00:00:04,694 --> 00:00:07,652 Typically, when you're building an application, 3 00:00:07,652 --> 00:00:11,671 you store application data in a database such as PostgresSQL or MongoDB. 4 00:00:11,671 --> 00:00:16,168 Depending on which database you choose, you'd likely use some kind of library, 5 00:00:16,168 --> 00:00:18,971 known as an ORM, or object-relational mapping, 6 00:00:18,971 --> 00:00:23,294 to facilitate the communication between your express app and your database. 7 00:00:23,294 --> 00:00:27,827 Some examples of ORM's include Mongoose for MongoDB and SQLize for 8 00:00:27,827 --> 00:00:29,348 SQL based databases. 9 00:00:29,348 --> 00:00:32,932 An ORM makes it easier to retrieve, manipulate, save, and 10 00:00:32,932 --> 00:00:35,125 validate the data in your database. 11 00:00:35,125 --> 00:00:40,095 For example, an ORM might provide a method to save new information to the database or 12 00:00:40,095 --> 00:00:43,110 create or update a new piece of data. 13 00:00:43,110 --> 00:00:46,430 While many of the basic concepts are the same, whether you're using Mongoose, 14 00:00:46,430 --> 00:00:50,570 or SQLize, or something else entirely, each technology has a specific 15 00:00:50,570 --> 00:00:54,510 way of doing things along with a breadth of advanced features. 16 00:00:54,510 --> 00:00:57,080 Learning to use an ORM can get complex, 17 00:00:57,080 --> 00:00:59,280 enough that it could warrant its own course. 18 00:00:59,280 --> 00:01:02,874 Same with setting up, configuring, and using a database. 19 00:01:02,874 --> 00:01:06,591 In this course we want to concentrate on just the concepts you need 20 00:01:06,591 --> 00:01:11,001 to know to create a rest API, independent of database and ORM technologies. 21 00:01:11,001 --> 00:01:16,367 For these reasons our application isn't going to use a database or an ORM. 22 00:01:16,367 --> 00:01:20,238 Instead, we've provided a module containing a few key functions for 23 00:01:20,238 --> 00:01:21,490 building out our app. 24 00:01:21,490 --> 00:01:24,854 Open up the project files if you don't have them open already. 25 00:01:24,854 --> 00:01:29,144 To keep things simple and focused we're going to store the data for 26 00:01:29,144 --> 00:01:32,371 our rest API in this json file called data.json. 27 00:01:32,371 --> 00:01:35,711 Think of the data.json file as a mock database, 28 00:01:35,711 --> 00:01:40,284 a data store where we can save and persist information for our API. 29 00:01:40,284 --> 00:01:44,554 Open it and you'll see that we have a JSON object containing an array of quotes. 30 00:01:44,554 --> 00:01:49,806 And each quote has a unique ID number, the text of the quote, and an author. 31 00:01:49,806 --> 00:01:53,466 Let's take a look at the records.js module. 32 00:01:53,466 --> 00:01:57,740 You can think of this module as a very, very basic ORM. 33 00:01:57,740 --> 00:02:02,220 As you can see, there's a method to get quotes from our data store, 34 00:02:02,220 --> 00:02:05,270 a method to get one quote, and so on. 35 00:02:05,270 --> 00:02:07,990 We'll see how to use these functions later in the course. 36 00:02:09,270 --> 00:02:12,039 Keep in mind that the purpose of the records.js module, 37 00:02:12,039 --> 00:02:16,110 is to allow us to work with some data for our API without a lot of overhead. 38 00:02:16,110 --> 00:02:19,250 So don't worry too much about understanding exactly what the code in 39 00:02:19,250 --> 00:02:20,920 this module is doing. 40 00:02:20,920 --> 00:02:23,760 We're actually making these functions available specifically so 41 00:02:23,760 --> 00:02:25,630 that you don't need to worry about it. 42 00:02:25,630 --> 00:02:29,410 Which is also purpose of ORMs, like Mongoose and SQLize. 43 00:02:29,410 --> 00:02:31,807 To abstract away some of the repetitive and or 44 00:02:31,807 --> 00:02:34,533 tedious parts of interacting with the data store. 45 00:02:34,533 --> 00:02:38,181 Once you've completed this course you'll be able to take the basic 46 00:02:38,181 --> 00:02:41,071 concepts you've learned here and apply them to ORM. 47 00:02:41,071 --> 00:02:45,372 After you're familiar with how to build an API, you'll have some conceptual knowledge 48 00:02:45,372 --> 00:02:49,039 that will help you dig into PosGres with SQLize, MongoDB with Mongoose, or 49 00:02:49,039 --> 00:02:53,970 whatever other technology you decide to use to store and interact with your data. 50 00:02:53,970 --> 00:02:58,480 In the next video, we'll refactor our get routes using the records.js module and 51 00:02:58,480 --> 00:02:59,820 our data.json file,