- Simple model on mongoose
- REST CRUD (create, read, update, delete) for the model created using koajs
- GraphQL Type for the model created, and expose it in a GraphQL endpoint
- Tests using [Jest]
- Authentication JWT
- Docker support
$ nvm use 8.6.0
$ npm install
Starting MongoDB server
$ docker run --name mongo -d -p 27017:27017 mongo
$ npm start
$ npm test
Docker
$ docker build --no-cache -t challenge .
$ docker run -d --name challenge -p 8080:3000 challenge
-
Method:
POST
-
Endpoint:
/v1/login
-
Input: The
Content-Type
HTTP header should be set toapplication/json
{ "user":"koa", "password": "password" }
-
Responses:
{ "token":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJyb2xlIjoiYWRtaW4iLCJpYXQiOjE1MDY5NDg2MDZ9.Q-VI1CKFXYf58TX7p9RV-NSyDR6vAZc6JEO58SIXBrs", "message": "Successfully logged in!" }
-
Method:
POST
-
Endpoint:
/v1/tasks
-
Input: The
Content-Type
HTTP header should be set toapplication/json
andAuthorization Bearer TOKEN
{ "description": "API", "type": "backend" }
-
Responses:
{ "__v": 0, "description": "API", "type": "backend", "_id": "59d23e3ff3ecdd28a4859675" }
- Method:
GET
- Endpoint:
/v1/tasks
- Input:
HTTP header should be set
Authorization Bearer TOKEN
- Responses:
[{ "__v": 0, "description": "API", "type": "backend", "_id": "59d23e3ff3ecdd28a4859675" }]
- Method:
GET
- Endpoint:
/v1/tasks/:id
- Input:
HTTP header should be set
Authorization Bearer TOKEN
- Responses:
{ "__v": 0, "description": "API", "type": "backend", "_id": "59d23e3ff3ecdd28a4859675" }
-
Method:
PUT
-
Endpoint:
/v1/tasks/:id
-
Input: The
Content-Type
HTTP header should be set toapplication/json
andAuthorization Bearer TOKEN
{ "description": "Database", "type": "DBA" }
-
Responses:
{ "_id": "59d23e3ff3ecdd28a4859675", "description": "Database", "type": "DBA", "__v": 0 }
- Method:
DELETE
- Endpoint:
/v1/tasks/:id
- Input:
HTTP header should be set
Authorization Bearer TOKEN
- Responses:
{ "ok": true }
- Method:
GET
- Endpoint:
/public/graphql?query={task{id,type,description}}
- Responses:
{ "data":{ "task":[ { "id": "59d2410af3ecdd28a4859676", "type": "backend", "description": "API" } ] } }
- Method:
GET
- Endpoint:
/public/graphql?query={task{id,type}}
- Responses:
{ "data":{ "task":[ { "id": "59d2410af3ecdd28a4859676", "type": "backend" } ] } }
- Method:
GET
- Endpoint:
/public/graphql?query={task{type}}
- Responses:
{ "data":{ "task":[ { "type": "backend" } ] } }
- Method:
GET
- Endpoint:
/public/graphql?query={task{description}}
- Responses:
{ "data":{ "task":[ { "description": "API" } ] } }