This is a bare-bones example of a contacts application providing a REST API to a MongoDB-backed model.
npm install
npm start
npm run start:dev
npm run lint
npm run lint:fix
The REST API to the example app is described below.
GET /api/contacts/
HTTP/1.1
Host: localhost:7070
Authorization: Bearer
HTTP/1.1 200 OK
Status: success
Content-Type: application/json
Body: "contacts": []
GET /api/contacts/:id
HTTP/1.1
Host: localhost:7070
Authorization: Bearer
HTTP/1.1 200 OK
Status: success
Content-Type: application/json
Body: "contact": { "favorite": boolean, "_id": string, "name": string, "email": string, "phone": string, "owner": object }
POST /api/contacts/
HTTP/1.1
Host: localhost:7070
Authorization: Bearer
Body: { "name": string, "email": string, "phone": string }
HTTP/1.1 201 OK
Status: success
Content-Type: application/json
Body: "contact": { "favorite": boolean, "_id": string, "name": string, "email": string, "phone": string, "owner": object, "__v": number }
PATCH /api/contacts/:id
HTTP/1.1
Host: localhost:7070
Authorization: Bearer
Body: { "favorite": boolean, "name": string, "email": string, "phone": string }
HTTP/1.1 200 OK
Status: success
Content-Type: application/json
Body: "contact": { "favorite": boolean, "_id": string, "name": string, "email": string, "phone": string, "owner": object }
PATCH /api/contacts/:id/favorite
HTTP/1.1
Host: localhost:7070
Authorization: Bearer
Body: { "favorite": boolean }
HTTP/1.1 200 OK
Status: success
Content-Type: application/json
Body: "contact": { "favorite": boolean, "_id": string, "name": string, "email": string, "phone": string, "owner": object }
DELETE /api/contacts/:id
HTTP/1.1
Host: localhost:7070
Authorization: Bearer
HTTP/1.1 200 OK
Status: contact deleted
Content-Type: application/json
GET /api/contacts?page=1
GET /api/contacts?limit=20
GET /api/contacts?favorite=true
GET /api/contacts?sortBy=name
GET /api/contacts?sortByDesc=name
GET /api/contacts?filter=email
HTTP/1.1
Host: localhost:7070
Authorization: Bearer
HTTP/1.1 200 OK
Content-Type: application/json
POST /api/users/signup
HTTP/1.1
Host: localhost:7070
Body: { "email": string, "subscription": string }
HTTP/1.1 201 Created
Content-Type: application/json
Body: { "user": { "email": string, "subscription": string } }
POST /api/users/login
HTTP/1.1
Host: localhost:7070
Body: { "email": string, "subscription": string }
HTTP/1.1 200 OK
Content-Type: application/json
Body: { "token": string, "user": { "email": string, "subscription": string } }
GET /api/users/verify/:verificationToken
HTTP/1.1
Host: localhost:7070
HTTP/1.1 200 OK
Status: 200 OK
Content-Type: application/json
Body: { "message": "Verification successful" }
POST /api/users/verify
HTTP/1.1
Content-Type: application/json
Host: localhost:7070
Body: { "email": string }
HTTP/1.1 200 OK
Status: 200 OK
Content-Type: application/json
Body: { "message": "Verification successful" }
POST /api/users/logout
HTTP/1.1
Host: localhost:7070
Authorization: Bearer
HTTP/1.1 204 No Content
GET /api/users/current
HTTP/1.1
Host: localhost:7070
Authorization: Bearer
HTTP/1.1 200 OK
Content-Type: application/json
Body: { "email": string, "subscription": string }
PATCH /api/users/subscription
HTTP/1.1
Host: localhost:7070
Authorization: Bearer
Body: { "subscription": ['starter', 'pro', 'business'], }
HTTP/1.1 200 OK
Status: updated
Content-Type: application/json
Body: { "user": { "email": string, "subscription": string } }
PATCH /api/users/avatars
HTTP/1.1
Host: localhost:7070
Content-Type: multipart/form-data
Authorization: Bearer
Body: { "avatar": image }
HTTP/1.1 200 OK
Status: updated
Content-Type: application/json
Body: { "avatarURL": string }