FernandoCagale / koa-challenge

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

koa-challenge

Build Status

js-semistandard-style

Challenge

  • 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

API Documentation

POST /v1/login

  • Method: POST

  • Endpoint: /v1/login

  • Input: The Content-Type HTTP header should be set to application/json

    {
      "user":"koa",
      "password": "password"
    }
  • Responses:

    {
      "token":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJyb2xlIjoiYWRtaW4iLCJpYXQiOjE1MDY5NDg2MDZ9.Q-VI1CKFXYf58TX7p9RV-NSyDR6vAZc6JEO58SIXBrs",
      "message": "Successfully logged in!"
    }

POST /v1/tasks

  • Method: POST

  • Endpoint: /v1/tasks

  • Input: The Content-Type HTTP header should be set to application/json and Authorization Bearer TOKEN

    {
        "description": "API",
        "type": "backend"
    }
  • Responses:

    {
        "__v": 0,
        "description": "API",
        "type": "backend",
        "_id": "59d23e3ff3ecdd28a4859675"
    }

GET /v1/tasks

  • Method: GET
  • Endpoint: /v1/tasks
  • Input: HTTP header should be set Authorization Bearer TOKEN
  • Responses:
    [{
        "__v": 0,
        "description": "API",
        "type": "backend",
        "_id": "59d23e3ff3ecdd28a4859675"
    }]

GET /v1/tasks/:id

  • Method: GET
  • Endpoint: /v1/tasks/:id
  • Input: HTTP header should be set Authorization Bearer TOKEN
  • Responses:
    {
        "__v": 0,
        "description": "API",
        "type": "backend",
        "_id": "59d23e3ff3ecdd28a4859675"
    }

PUT /v1/tasks/:id

  • Method: PUT

  • Endpoint: /v1/tasks/:id

  • Input: The Content-Type HTTP header should be set to application/json and Authorization Bearer TOKEN

    {
        "description": "Database",
        "type": "DBA"
    }
  • Responses:

    {
        "_id": "59d23e3ff3ecdd28a4859675",
        "description": "Database",
        "type": "DBA",
        "__v": 0
    }

DELETE /v1/tasks/:id

  • Method: DELETE
  • Endpoint: /v1/tasks/:id
  • Input: HTTP header should be set Authorization Bearer TOKEN
  • Responses:
    {
        "ok": true
    }

GET /public/graphql

  • Method: GET
  • Endpoint: /public/graphql?query={task{id,type,description}}
  • Responses:
    {
        "data":{
            "task":[
                {
                    "id": "59d2410af3ecdd28a4859676",
                    "type": "backend",
                    "description": "API"
                }
            ]
        }
    }

GET /public/graphql

  • Method: GET
  • Endpoint: /public/graphql?query={task{id,type}}
  • Responses:
    {
        "data":{
            "task":[
                {
                    "id": "59d2410af3ecdd28a4859676",
                    "type": "backend"
                }
            ]
        }
    }

GET /public/graphql

  • Method: GET
  • Endpoint: /public/graphql?query={task{type}}
  • Responses:
    {
        "data":{
            "task":[
                {
                    "type": "backend"
                }
            ]
        }
    }

GET /public/graphql

  • Method: GET
  • Endpoint: /public/graphql?query={task{description}}
  • Responses:
    {
        "data":{
            "task":[
                {
                    "description": "API"
                }
            ]
        }
    }

About


Languages

Language:JavaScript 98.1%Language:Shell 1.9%