This project uses REST API design, Node.js, and Express to create API routes, along with Mongoose and MongoDB for data modeling, validation, and persistence.
The API will provide a way for users to:
- add a new user
- review educational courses: users can see a list of courses in a database;
- add courses to the database;
- add reviews for a specific course.
-
Clone the repo:
git clone [email protected]:apalm112/FSJS-Course-Rating-API-Express.git
-
cd
into the project folder & install dependencies:$ npm i
-
Run:
$ mongod
-
Load the seed-data by opening a separate terminal tab,
cd
to thesrc/database/seed-data
folder & run the commands:
$ mongoimport --db api --collection users --type=json --jsonArray --file users.json
$ mongoimport --db api --collection reviews --type=json --jsonArray --file reviews.json
$ mongoimport --db api --collection courses --type=json --jsonArray --file courses.json
-
To run the API locally, in a new terminal tab enter:
$ npm start
ornodemon
-
Now you can use Postman to test the API routes, such as
GET localhost:5000/api/courses
. -
POST a new user enter the data in this format:
{
"fullName": "Bob Jones",
"emailAddress": "[email protected]",
"password": "password"
}
- POST a new review in this format, with valid email & password in Postmans Basic Auth:
{
"rating": 4,
"review": "Here is a new review, such wow."
}
- POST a new course
{
"reviews": [],
"title": "New Course Title",
"description": "Lorem gibson euro-pop narrative Tessier-Ashpool rain realism human RAF assassin carbon sign shanty town sub-orbital ICE Tokyo.",
"estimatedTime": "12 hours",
"materialsNeeded": "A Dungeon Master and lots of other stuff",
"steps": [
{
"stepNumber": 1,
"title": "D&D Financing with Blockchain",
"description": "Collect gold pieces."
}
]
}
- Run the Tests in the console:
cd
into test/
$ npm test