Skip to content

andyhap/user_management_api_task

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

How to Use

create file. env

First, make sure to create a .env file in the root project and fill it with the following format:

PORT=5000
DB_USER=postgres
DB_HOST=localhost
DB_NAME=(your db name)
DB_PASS=(your db password)
DB_PORT=(your cb port)
CLOUDINARY_NAME=(your cloudinary name)
CLOUDINARY_KEY=(your cloudinary key)
CLOUDINARY_SECRET=(your caludinary secret)
JWT_SECRET=(jwt secret)

Make sure the folder structure matches the image.

image

Running user_management_api

Next, you can run the user_management_api by typing:

node index.js
# or
npm start

If successful, a message will appear in the terminal:

✅ Server running at http://localhost:5000

Testing Using Postman

After running and seeing the message "Server running on port 5000" in the terminal, enter the local host link http://localhost:5000/api/(auth or user)/(action for auth or user).

/api/auth/register	POST	Registrasi user baru
/api/auth/login	POST	Login dan mendapatkan JWT
/api/users	GET	Menampilkan semua user (dengan token)
/api/users/avatar	POST	Upload avatar user
/api/users/:id	PUT	Update user berdasarkan ID
/api/users/:id	DELETE	Hapus user berdasarkan ID

catatan: All /users endpoints require an Authorization header:

Authorization: Bearer <jwt_token>
image

see postman documentation here: https://documenter.getpostman.com/view/49108277/2sB3QRnSrq

Documentation with Swagger

After running, open your browser and go to the local host link:

http://localhost:5000/api-docs

After opening it, an interactive documentation display with Swagger UI will appear.

image

Auth:

  1. In the auth section, register first.
  2. Next, log in and save the generated token.
  3. Insert the generated token into the Authorization header.

User: All user-related features can be executed directly since the token has already been added to the Authorization header.

  1. GET – Display all users
  2. POST – Upload user avatar
  3. PUT – Update user
  4. DELETE – Delete user

About

Assignment on Implementing CRUD API with Authentication, Security, and File Upload using cloudinary

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published