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/bootcamps
Headers:
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/bootcamps
Get single bootcamp. Provide bootcamp id as param.
Access: Public
Endpoint:
Method: GET
URL: {{URL}}/api/v1/bootcamps/:bootcampId
Find bootcamp within radius of the pincode. Provide distance in meter.
Access: Public
Endpoint:
Method: GET
URL: {{URL}}/api/v1/bootcamps/:pincode/:distance
Update 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/:bootcampId
Headers:
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/photo
Headers:
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/:bootcampId
Headers:
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/courses
Headers:
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/courses
Get all courses from all bootcamps
Access: Public
Endpoint:
Method: GET
URL: {{URL}}/api/v1/courses
Headers:
Key | Value | Description |
---|---|---|
Content-Type | application/json |
Get a single course with given id.
Access: Public
Endpoint:
Method: GET
URL: {{URL}}/api/v1/courses/:id
Update course details. Only publisher published bootcamp and admin will have access to this route.
Access: Private
Endpoint:
Method: PUT
URL: {{URL}}/api/v1/courses/:id
Headers:
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/:id
Headers:
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/register
Headers:
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/login
Headers:
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-password
Headers:
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/me
Headers:
Key | Value | Description |
---|---|---|
Content-Type | application/json |
Logout user.
Access: Public
Endpoint:
Method: GET
URL: {{URL}}/api/v1/auth/logout
Reset password.
Access: Public
Endpoint:
Method: PUT
URL: {{URL}}/api/v1/auth/reset-password/:resetToken
Headers:
Key | Value | Description |
---|---|---|
Content-Type | application/json |
Body:
{
"password": "12345"
}
Update user details.
Access: Private
Endpoint:
Method: PUT
URL: {{URL}}/api/v1/auth/update-user
Headers:
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-password
Headers:
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/admin
Get single user with id.
Access: Private/Admin
Endpoint:
Method: GET
URL: {{URL}}/api/v1/auth/admin/:id
Create user with admin access
Access: Private/Admin
Endpoint:
Method: POST
URL: {{URL}}/api/v1/auth/admin
Headers:
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/:id
Headers:
Key | Value | Description |
---|---|---|
Content-Type | application/json |
Body:
{
"role": "publisher"
}
Delete user.
Access: Private/Admin
Endpoint:
Method: DELETE
URL: {{URL}}/api/v1/auth/admin/:id
Headers:
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/reviews
Get reviews from individual bootcamps.
Access: Public
Endpoint:
Method: GET
URL: {{URL}}/api/v1/bootcamps/:bootcampId/reviews
Get single reviews.
Access: Public
Endpoint:
Method: GET
URL: {{URL}}/api/v1/reviews/:id
Post review on individual bootcamp.
Access: Private
Endpoint:
Method: POST
URL: {{URL}}/api/v1/bootcamps/:bootcampId/reviews
Headers:
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/:id
Headers:
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/:id
Headers:
Key | Value | Description |
---|---|---|
Content-Type | application/json |