Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Preview
Start a free Courses trial
to watch this video
To keep things simple and focused, we’re going to store the data for our REST API in this JSON file called data.json. Think of the data.json file as a mock database-- a datastore where we can save and persist information for our API.
[MUSIC]
0:00
Typically, when you're
building an application,
0:04
you store application data in a database
such as PostgresSQL or MongoDB.
0:07
Depending on which database you choose,
you'd likely use some kind of library,
0:11
known as an ORM, or
object-relational mapping,
0:16
to facilitate the communication between
your express app and your database.
0:18
Some examples of ORM's include
Mongoose for MongoDB and SQLize for
0:23
SQL based databases.
0:27
An ORM makes it easier to retrieve,
manipulate, save, and
0:29
validate the data in your database.
0:32
For example, an ORM might provide a method
to save new information to the database or
0:35
create or update a new piece of data.
0:40
While many of the basic concepts are the
same, whether you're using Mongoose,
0:43
or SQLize, or something else entirely,
each technology has a specific
0:46
way of doing things along with
a breadth of advanced features.
0:50
Learning to use an ORM can get complex,
0:54
enough that it could
warrant its own course.
0:57
Same with setting up, configuring,
and using a database.
0:59
In this course we want to concentrate
on just the concepts you need
1:02
to know to create a rest API, independent
of database and ORM technologies.
1:06
For these reasons our application isn't
going to use a database or an ORM.
1:11
Instead, we've provided a module
containing a few key functions for
1:16
building out our app.
1:20
Open up the project files if you
don't have them open already.
1:21
To keep things simple and
focused we're going to store the data for
1:24
our rest API in this json
file called data.json.
1:29
Think of the data.json
file as a mock database,
1:32
a data store where we can save and
persist information for our API.
1:35
Open it and you'll see that we have a JSON
object containing an array of quotes.
1:40
And each quote has a unique ID number,
the text of the quote, and an author.
1:44
Let's take a look at
the records.js module.
1:49
You can think of this module as a very,
very basic ORM.
1:53
As you can see, there's a method
to get quotes from our data store,
1:57
a method to get one quote, and so on.
2:02
We'll see how to use these
functions later in the course.
2:05
Keep in mind that the purpose
of the records.js module,
2:09
is to allow us to work with some data for
our API without a lot of overhead.
2:12
So don't worry too much about
understanding exactly what the code in
2:16
this module is doing.
2:19
We're actually making these
functions available specifically so
2:20
that you don't need to worry about it.
2:23
Which is also purpose of ORMs,
like Mongoose and SQLize.
2:25
To abstract away some of
the repetitive and or
2:29
tedious parts of interacting
with the data store.
2:31
Once you've completed this course
you'll be able to take the basic
2:34
concepts you've learned here and
apply them to ORM.
2:38
After you're familiar with how to build an
API, you'll have some conceptual knowledge
2:41
that will help you dig into PosGres
with SQLize, MongoDB with Mongoose, or
2:45
whatever other technology you decide to
use to store and interact with your data.
2:49
In the next video, we'll refactor our get
routes using the records.js module and
2:53
our data.json file,
2:58
You need to sign up for Treehouse in order to download course files.
Sign up