Skip to content

Basant1Saini/user-api-assignment

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

User Management REST API

A simple RESTful API for managing users with Node.js and Express.

🔗 GitHub Repository: https://github.com/Basant1Saini/user-api-assignment

🚀 Getting Started

What You Need

  • Node.js installed on your computer
  • VS Code (Visual Studio Code)
  • Thunder Client extension for VS Code

Installation

  1. Open terminal in this folder
  2. Install dependencies:
npm install
  1. Start the server:
npm start
  1. You should see:
Server running on http://localhost:3000

📚 API Endpoints

1. Get All Users

GET http://localhost:3000/users

Returns a list of all users.

2. Get One User

GET http://localhost:3000/users/1

Returns the user with ID 1.

3. Create New User

POST http://localhost:3000/user
Content-Type: application/json

{
  "firstName": "Arjun",
  "lastName": "Patel",
  "hobby": "Photography"
}

Creates a new user.

4. Update User

PUT http://localhost:3000/user/1
Content-Type: application/json

{
  "hobby": "Yoga"
}

Updates user with ID 1. You can update any field.

5. Delete User

DELETE http://localhost:3000/user/3

Deletes the user with ID 3.

🧪 How to Test with Thunder Client

Step 1: Install Thunder Client

  1. Open VS Code
  2. Click Extensions icon (or press Cmd+Shift+X)
  3. Search for "Thunder Client"
  4. Click "Install"

Step 2: Open Thunder Client

  1. Click the Thunder Client icon in the left sidebar (⚡)
  2. Click "New Request" button

Step 3: Test Each Endpoint

Test 1: Get All Users

  1. Select method: GET
  2. Enter URL: http://localhost:3000/users
  3. Click Send
  4. You should see 3 users in the response
  5. Take a screenshot

Test 2: Get One User

  1. Select method: GET
  2. Enter URL: http://localhost:3000/users/1
  3. Click Send
  4. You should see Anshika's details
  5. Take a screenshot

Test 3: Create New User

  1. Select method: POST
  2. Enter URL: http://localhost:3000/user
  3. Click on Body tab
  4. Select JSON format
  5. Paste this:
{
  "firstName": "Arjun",
  "lastName": "Patel",
  "hobby": "Photography"
}
  1. Click Send
  2. You should get status 201 Created
  3. Take a screenshot

Test 4: Create User with Missing Data (Error Test)

  1. Select method: POST
  2. Enter URL: http://localhost:3000/user
  3. In Body tab (JSON), paste:
{
  "firstName": "Arjun"
}
  1. Click Send
  2. You should get status 400 Bad Request with error message
  3. Take a screenshot

Test 5: Update User

  1. Select method: PUT
  2. Enter URL: http://localhost:3000/user/1
  3. In Body tab (JSON), paste:
{
  "hobby": "Yoga"
}
  1. Click Send
  2. You should see updated user with new hobby
  3. Take a screenshot

Test 6: Delete User

  1. Select method: DELETE
  2. Enter URL: http://localhost:3000/user/3
  3. Click Send
  4. You should get confirmation that Priya was deleted
  5. Take a screenshot

Test 7: Delete Non-existent User (Error Test)

  1. Select method: DELETE
  2. Enter URL: http://localhost:3000/user/999
  3. Click Send
  4. You should get status 404 Not Found
  5. Take a screenshot

📂 Project Structure

user-api/
├── server.js        # Main file with all the code
├── package.json     # Project info and dependencies
└── README.md        # This file

✅ Features Included

  • All 5 CRUD operations (Create, Read, Update, Delete)
  • Request logging (see console when requests come in)
  • Input validation (checks if data is correct)
  • Error handling (friendly error messages)
  • In-memory storage (data stored in array)

💡 Tips

Server Tips:

  • Server must be running to test the API
  • Use Ctrl+C to stop the server
  • Check the terminal for request logs
  • All data is lost when you restart the server (in-memory storage)

Thunder Client Tips:

  • Save your requests by clicking the Save button (give it a name like "Get All Users")
  • Create a collection called "User API" to organize all requests
  • Use the History tab to see previous requests
  • Take clear screenshots showing: URL, Method, Body (if applicable), and Response

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published