A JSON Server-based API with custom endpoints for user management.
npm installThis API requires authentication using an API key.
The default API key is: your-default-api-key-2025
npm run generate-key# Create .env file
cp .env.example .env
# Set your API key
API_KEY=your-secure-api-key-herenpm startnpm run devnpm run server/health)
Include your API key in one of these ways:
- Header:
x-api-key: YOUR_API_KEY - Header:
api-key: YOUR_API_KEY - Query Parameter:
?apiKey=YOUR_API_KEY
| Method | Endpoint | Description |
|---|---|---|
| GET | /health |
Server health check and API information |
| Method | Endpoint | Description |
|---|---|---|
| GET | /users |
Get all users |
| GET | /users/:id |
Get user by ID |
| POST | /users |
Create new user |
| PUT | /users/:id |
Update user by ID |
| PATCH | /users/:id |
Partially update user by ID |
| DELETE | /users/:id |
Delete user by ID |
| Method | Endpoint | Description | Example |
|---|---|---|---|
| GET | /api/user/:username |
Get user by username (primary identifier) | /api/user/AB123456 |
| GET | /api/users/:username |
Get user by username (alternative route) | /api/users/CD789012 |
| GET | /api/user/email/:email |
Get user by email | /api/user/email/[email protected] |
| GET | /api/user/role/:role |
Get users by role | /api/user/role/Sales |
| GET | /api/user/profile/:username |
Get user profile by username (limited fields) | /api/user/profile/XD431834 |
| Method | Endpoint | Description | Example |
|---|---|---|---|
| PUT | /api/users/:username |
Update user by username | /api/users/AB123456 |
| DELETE | /api/users/:username |
Delete user by username | /api/users/AB123456 |
| Method | Endpoint | Description | Example |
|---|---|---|---|
| GET | /api/users/search |
Search users with multiple filters | /api/users/search?q=john&role=Admin |
q: Search in username, firstName, lastName, emailAddressrole: Filter by primaryRoleuserType: Filter by userType (D, A, U)accessLevel: Filter by accessLevel (Admin, Manager, User)
curl -X GET http://localhost:3000/healthcurl -X GET http://localhost:3000/api/user/AB123456 \
-H "x-api-key: your-default-api-key-2025"curl -X GET "http://localhost:3000/api/user/AB123456?apiKey=your-default-api-key-2025"curl -X GET http://localhost:3000/api/users/CD789012 \
-H "api-key: your-default-api-key-2025"curl -X GET http://localhost:3000/api/user/email/[email protected] \
-H "x-api-key: your-default-api-key-2025"curl -X GET http://localhost:3000/api/user/role/Sales \
-H "x-api-key: your-default-api-key-2025"curl -X GET http://localhost:3000/api/user/profile/XD431834 \
-H "x-api-key: your-default-api-key-2025"curl -X PUT http://localhost:3000/api/users/AB123456 \
-H "Content-Type: application/json" \
-H "x-api-key: your-default-api-key-2025" \
-d '{"firstName": "Jonathan", "accessLevel": "SuperAdmin"}'curl -X DELETE http://localhost:3000/api/users/AB123456 \
-H "x-api-key: your-default-api-key-2025"# Search by name
curl -X GET "http://localhost:3000/api/users/search?q=john" \
-H "x-api-key: your-default-api-key-2025"
# Search by multiple criteria
curl -X GET "http://localhost:3000/api/users/search?role=Sales&userType=D" \
-H "x-api-key: your-default-api-key-2025"
# Search with access level
curl -X GET "http://localhost:3000/api/users/search?accessLevel=Admin" \
-H "x-api-key: your-default-api-key-2025"{
"error": "API key is required",
"message": "Please provide an API key in the x-api-key header or apiKey query parameter"
}{
"error": "Invalid API key",
"message": "The provided API key is not valid"
}JSON Server also supports these query parameters on the basic endpoints:
- Filtering:
/users?primaryRole=Sales - Sorting:
/users?_sort=firstName&_order=asc - Pagination:
/users?_page=1&_limit=10 - Full-text search:
/users?q=nissan - Range:
/users?id_gte=1&id_lte=3
Each user object contains:
id: Unique identifierusername: User's usernameuserType: Type of user (D, A, U)firstName: User's first namelastName: User's last nameemailAddress: User's emailphoneNumber: User's phone numberlocale: User's localepostalCode: User's postal codeprimaryRegion: User's primary regionallowedRegions: Regions user has access toLMSPersonId: LMS person identifierprimaryChannelCode: Primary channel codeEID: Employee IDprimaryRole: User's primary roleprimaryOtherRoles: Other rolesprimarySpecialDesignations: Special designationsaccessLevel: User's access levelaffiliateCode: Affiliate codeprimaryDealershipCode: Primary dealership codedealerType: Type of dealerallowedDealerships: Dealerships user has access toprimaryDealerPosition: User's positionprimaryNMACDealerCode: NMAC dealer codeallowedNMACDealerships: NMAC dealerships user has access toUDEF3,UDEF4,UDEF5: Custom user-defined fields
- Returns
404with{"error": "User not found"}for non-existent users - Returns empty object
{}for some endpoints when user doesn't exist - Returns empty array
[]for search results with no matches
db.json: Database file with user dataserver.js: Custom server with additional endpointsmiddleware.js: Custom middleware for user-specific endpointsroutes.json: Custom route mappingspackage.json: Project configuration