Backend API for DevCamper application, which is a bootcamp directory website. Followed from Brad Traversey API masterclass.
Rename "config/config.env.env" to "config/config.env" and update the values/settings to your own
npm install
# Run in dev mode
npm run dev
# Run in prod mode
npm start
To seed the database with users, bootcamps, courses and reviews with data from the "./data" folder, run
# Destroy all data
node seeder -d
# Import all data
node seeder -i
Extensive documentation with examples here
Bootcamps will be created and maintained by users with role "publisher".
To provide different courses publisher need to create bootcamp to store all the courses of same domain under one bootcamp.
Each bootcamp can have multiple courses but one publisher can have only one bootcamp
Create a bootcamp
Access: Private
Endpoint:
Method: POST
URL: {{URL}}/api/v1/bootcampsHeaders:
| Key | Value | Description |
|---|---|---|
| Content-Type | application/json |
Body:
{
"name": "Devcentral Bootcamp",
"description": "Is coding your passion? Codemasters will give you the skills and the tools to become the best developer possible. We specialize in front end and full stack web development",
"website": "https://devcentral.com",
"phone": "(444) 444-4444",
"email": "enroll@devcentral.com",
"address": "45 Upper College Rd Kingston RI 02881",
"careers": [
"Mobile Development",
"Web Development",
"Data Science",
"Business"
],
"housing": false,
"jobAssistance": true,
"jobGuarantee": true,
"acceptGi": true
}Get all bootcamps
Access: Public
Endpoint:
Method: GET
URL: {{URL}}/api/v1/bootcampsGet single bootcamp. Provide bootcamp id as param.
Access: Public
Endpoint:
Method: GET
URL: {{URL}}/api/v1/bootcamps/:bootcampIdFind bootcamp within radius of the pincode. Provide distance in meter.
Access: Public
Endpoint:
Method: GET
URL: {{URL}}/api/v1/bootcamps/:pincode/:distanceUpdate details of the bootcamp. Only publisher published bootcamp and admin will have access to this route.
Access: Private
Endpoint:
Method: PUT
URL: {{URL}}/api/v1/bootcamps/:bootcampIdHeaders:
| Key | Value | Description |
|---|---|---|
| Content-Type | application/json |
Body:
{ "name": "New Devworks Bootcamp"}Upload bootcamp cover photo. Only publisher published bootcamp and admin will have access to this route. Only PNG, JPG, JPEG, SVG files with size less than 1MB will be accepted.
Access: Private
Endpoint:
Method: PUT
URL: {{URL}}/api/v1/bootcamps/:bootcampId/photoHeaders:
| Key | Value | Description |
|---|---|---|
| Content-Type | application/json |
Body:
| Key | Value | Description |
|---|---|---|
| file | temp.png |
Delete bootcamp. Only publisher published bootcamp and admin will have access to this route.
Access: Private
Endpoint:
Method: DELETE
URL: {{URL}}/api/v1/bootcamps/:bootcampIdHeaders:
| Key | Value | Description |
|---|---|---|
| Content-Type | application/json |
Courses belongs to bootcamps. One bootcamp can have multiple courses but each course must belong to a single bootcamp.
Create new course
Access: Private
Endpoint:
Method: POST
URL: {{URL}}/api/v1/bootcamps/:bootcampId/coursesHeaders:
| Key | Value | Description |
|---|---|---|
| Content-Type | application/json |
Body:
{
"title": "Front End Web Development",
"description": "This course will provide you with all of the essentials to become a successful frontend web developer. You will learn to master HTML, CSS and front end JavaScript, along with tools like Git, VSCode and front end frameworks like Vue",
"weeks": 8,
"tuition": 8000,
"minimumSkill": "beginner",
"scholarhipsAvailable": true
}Get courses from individual bootcamps.
Access: Public
Endpoint:
Method: GET
URL: {{URL}}/api/v1/bootcamps/:bootcampId/coursesGet all courses from all bootcamps
Access: Public
Endpoint:
Method: GET
URL: {{URL}}/api/v1/coursesHeaders:
| Key | Value | Description |
|---|---|---|
| Content-Type | application/json |
Get a single course with given id.
Access: Public
Endpoint:
Method: GET
URL: {{URL}}/api/v1/courses/:idUpdate course details. Only publisher published bootcamp and admin will have access to this route.
Access: Private
Endpoint:
Method: PUT
URL: {{URL}}/api/v1/courses/:idHeaders:
| Key | Value | Description |
|---|---|---|
| Content-Type | application/json |
Body:
{
"tuition": 11000
}Delete course with id. Only publisher published bootcamp and admin will have access to this route.
Access: Private
Endpoint:
Method: DELETE
URL: {{URL}}/api/v1/courses/:idHeaders:
| Key | Value | Description |
|---|---|---|
| Content-Type | application/json |
Body:
{"minimumSkill": "beginner"}Concerned with register, login, update password, reset password routes.
Register user. JWT token is generated.
Access: Public
Endpoint:
Method: POST
URL: {{URL}}/api/v1/auth/registerHeaders:
| Key | Value | Description |
|---|---|---|
| Content-Type | application/json |
Body:
{
"name": "Teset account",
"email":"test@mail.com",
"password":"1234",
"role": "user"
}Login user. JWT token is generated.
Access: Public
Endpoint:
Method: POST
URL: {{URL}}/api/v1/auth/loginHeaders:
| Key | Value | Description |
|---|---|---|
| Content-Type | application/json |
Body:
{
"name": "Publisher Account",
"email": "publisher@gmail.com",
"role": "publisher",
"password": "123456"
}Forgot password for generating reset password token and sending emails with reset token URL.
Access: Public
Endpoint:
Method: POST
URL: {{URL}}/api/v1/auth/forgot-passwordHeaders:
| Key | Value | Description |
|---|---|---|
| Content-Type | application/json |
Body:
{
"email": "publisher@gmail.com"
}Get logged in user.
Access: Private
Endpoint:
Method: GET
URL: {{URL}}/api/v1/auth/meHeaders:
| Key | Value | Description |
|---|---|---|
| Content-Type | application/json |
Logout user.
Access: Public
Endpoint:
Method: GET
URL: {{URL}}/api/v1/auth/logoutReset password.
Access: Public
Endpoint:
Method: PUT
URL: {{URL}}/api/v1/auth/reset-password/:resetTokenHeaders:
| Key | Value | Description |
|---|---|---|
| Content-Type | application/json |
Body:
{
"password": "12345"
}Update user details.
Access: Private
Endpoint:
Method: PUT
URL: {{URL}}/api/v1/auth/update-userHeaders:
| Key | Value | Description |
|---|---|---|
| Content-Type | application/json |
Body:
{
"name": "Publisher 2"
}Update password if user logged in.
Access: Private
Endpoint:
Method: PUT
URL: {{URL}}/api/v1/auth/update-passwordHeaders:
| Key | Value | Description |
|---|---|---|
| Content-Type | application/json |
Body:
{
"currentPassword": "12345",
"newPassword": "123456"
}Admin routes for CURD operations on users. Admin is super user and have access to all the routes and controls.
For creating admin user, follow these steps:
- Create user with any role
- Change role manually in database to "admin"
Get all registered users.
Access: Private/Admin
Endpoint:
Method: GET
URL: {{URL}}/api/v1/auth/adminGet single user with id.
Access: Private/Admin
Endpoint:
Method: GET
URL: {{URL}}/api/v1/auth/admin/:idCreate user with admin access
Access: Private/Admin
Endpoint:
Method: POST
URL: {{URL}}/api/v1/auth/adminHeaders:
| Key | Value | Description |
|---|---|---|
| Content-Type | application/json |
Body:
{
"name": "Test Account",
"email": "test@mail.com",
"password": "123456"
}Update user details.
Access: Private/Admin
Endpoint:
Method: PUT
URL: {{URL}}/api/v1/auth/admin/:idHeaders:
| Key | Value | Description |
|---|---|---|
| Content-Type | application/json |
Body:
{
"role": "publisher"
}Delete user.
Access: Private/Admin
Endpoint:
Method: DELETE
URL: {{URL}}/api/v1/auth/admin/:idHeaders:
| Key | Value | Description |
|---|---|---|
| Content-Type | application/json |
Body:
{
"role": "publisher"
}Reviews can be published by users with role "user" and "admin". One user can only published single review on each bootcamp.
Get all reviews from all bootcamps.
Access: Public
Endpoint:
Method: GET
URL: {{URL}}/api/v1/reviewsGet reviews from individual bootcamps.
Access: Public
Endpoint:
Method: GET
URL: {{URL}}/api/v1/bootcamps/:bootcampId/reviewsGet single reviews.
Access: Public
Endpoint:
Method: GET
URL: {{URL}}/api/v1/reviews/:idPost review on individual bootcamp.
Access: Private
Endpoint:
Method: POST
URL: {{URL}}/api/v1/bootcamps/:bootcampId/reviewsHeaders:
| Key | Value | Description |
|---|---|---|
| Content-Type | application/json |
Body:
{
"title": "Great Experience",
"text": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec viverra feugiat mauris id viverra. Duis luctus ex sed facilisis ultrices. Curabitur scelerisque bibendum ligula, quis condimentum libero fermentum in. Aenean erat erat, aliquam in purus a, rhoncus hendrerit tellus. Donec accumsan justo in felis consequat sollicitudin. Fusce luctus mattis nunc vitae maximus. Curabitur semper felis eu magna laoreet scelerisque",
"rating": "8"
}Update reviews.
Access: Private
Endpoint:
Method: PUT
URL: {{URL}}/api/v1/reviews/:idHeaders:
| Key | Value | Description |
|---|---|---|
| Content-Type | application/json |
Body:
{
"title": "Splendid Experience",
"rating": "10"
}Delete a review.
Access: Private
Endpoint:
Method: DELETE
URL: {{URL}}/api/v1/reviews/:idHeaders:
| Key | Value | Description |
|---|---|---|
| Content-Type | application/json |