8000 GitHub - knrt10/Todo-backendAPI: Backend for a To-Do application. This is part of series of medium article that I wrote.
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

knrt10/Todo-backendAPI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

14 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Build Status Codacy Badge codecov MIT Licence

Contents

  1. About the Project
  2. Requirements
  3. Tech Stack and Packages used
  4. Initial Setup
  5. Working with docker
  6. Running Project locally
  7. API of application
  8. Support

About the Project

Just a simple but effective backend for a todo application.

Requirements

Tech Stack and Packages used

  • Docker used to contain dependencies and tooling
  • node >= 8.9.0
  • npm >= 5.5.1
  • TypeScript >= 3.0.1
  • graphql for making API queries
  • mongoDb for database
  • winston for logging/monitoring application
  • gulp for solving problem of repetition
  • bluebird for promises
  • mocha and chai for testing
  • nyc for code coverage
  • ts-node for traspiling TypeScript on the server so that it could be used in Node.js
  • tslint for linting code

Initial Setup

// Cloning the repository

git clone https://github.com/knrt10/Todo-backendAPI.git

// Change directory to project folder

cd Todo-backendAPI/

Working with docker

After following above intital steps, its very easy to access the api using docker. All you need is to do it follow small steps given below.

Changing shared/config.ts

Initial mongoDb is setup for localhost. master branch contains setup for running server using npm so you need to change branch

git checkout docker

After changing that run this command

npm run dockerStart

This will run a script scripts/dockerCompose.sh and create docker image and with help of docker-compose.yml from our project directory it will start server automatically. Now to access the application proceed to API of application.

To Stop Our Docker process type this command in your terminal

npm run dockerStop

Running Project locally

Initial Steps

Follow these simple steps

  1. Installing dependencies
    • npm i
    • This will create a node_modules folder.
  2. Building the project
    • After dependencies are installed run npm run build
    • This will build the application and create a dist/ folder
  3. Starting mongodb Server
    • You need to start your mongodb server for your OS. For Mac and Unix it is mongod.
  4. Running the application
    • Start your application by running npm start or npm run dev
  5. Accessing API of application
  6. Stopping the application
    • press ctrl + c in your terminal where server is runnning.
  7. Running docker again.

Running Tests

IMPORTANT:- To run tests your config should be localDatabase: true in shared/config.ts and your local mongoDB server should be running. If so then run simple command

npm run build && npm run coverage

Linting Code

You can lint the code automatically by running this is your terminal

npm run lint

API of application

This is simple API of application. Go to http://localhost:3000/graphql or open GraphQL-Playground and enter above URL for testing your API.

Registering User

mutation registerUser($input: UserInputRegister) {
  registerUser(input: $input) {
    code
    message
    data {
      token
      success
      user {
        id
        createdAt
        username
        name
        password
        updatedAt
      }
    }
  }
}

and input

{
  "input": {
    "username": "knrt10",
    "name": "Kautilya",
    "password": "test"
  }
}

Login User

query loginUser($input: UserInputLogin) {
  loginUser(input: $input) {
    code,
    message,
    data {
      success
      user {
        id
        name
        username
        password
      }
      token
    }
  }
}
and input

{
  "input": {
    "username": "knrt10",
    "password": "test"
  }
}

Profile of User

query profileUser{
  profileUser {
    code
    message
    data {
      success
      token
      user {
        name
      }
    }
  }
}

and headers

{
  "x-access-token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjVjMjBkNzRiMGJjNTc4MTRmOGE4YjQ5ZSIsImlhdCI6MTU0NTY1NzI5OSwiZXhwIjoxNTQ1NzQwMDk5fQ.wG4i5gvxTG6Ts-6jfQp1ZdDtF6RysMh-WtXQYACBl74"
}

Create TODO

mutation addTodo($input: todoInput) {
  addTodo(input: $input) {
    code
    message
    data {
      success
     	todo {
        id
        postedByid
        description
        updatedAt
        createdAt
        name
      }
    }
  }
}

and input

{
  "input": {
    "title": "knrt10",
    "description": "test"
  }
}

and also headers

{
  "x-access-token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjVjMjBkNzRiMGJjNTc4MTRmOGE4YjQ5ZSIsImlhdCI6MTU0NTY1NzI5OSwiZXhwIjoxNTQ1NzQwMDk5fQ.wG4i5gvxTG6Ts-6jfQp1ZdDtF6RysMh-WtXQYACBl74"
}

Get all todos

query todoUsers {
  todoUsers{
    code
    message
    data {
      success
      todos {
        title
        description
      }
    }
  }
}

and also headers

{
  "x-access-token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjVjMjBkNzRiMGJjNTc4MTRmOGE4YjQ5ZSIsImlhdCI6MTU0NTY1NzI5OSwiZXhwIjoxNTQ1NzQwMDk5fQ.wG4i5gvxTG6Ts-6jfQp1ZdDtF6RysMh-WtXQYACBl74"
}

Updating a Todo

mutation updateTodo($input: todoInputUpdate) {
  updateTodo(input: $input) {
    code
    message
    data {
      success
     	todo {
        id
        postedByid
        description
        updatedAt
        createdAt
        name
        title
      }
    }
  }
}

and input 
{
  "input": {
    "id": "5c2503576c89915ab8ac3572",
    "title": "Woooa this is working?",
    "description": "Yep."
  }
}

and also header
{
  "x-access-token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjVjMjUwMzIwNmM4OTkxNWFiOGFjMzU3MSIsImlhdCI6MTU0NTkyOTUwNCwiZXhwIjoxNTQ2MDEyMzA0fQ.hn4csdGR5w-2yXWVUEmW4wh8U0s5SfWXfClmP0jVgOY"
}

Deleting a Todo

mutation deleteTodo($id: String) {
  deleteTodo(id: $id) {
    code
    message
    data {
      success
    }
  }
}

and input

{
  "id": "5c20ecda2e62db1ae4d9ff42"
}

and also headers

{
  "x-access-token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjVjMjBkNzRiMGJjNTc4MTRmOGE4YjQ5ZSIsImlhdCI6MTU0NTY1NzI5OSwiZXhwIjoxNTQ1NzQwMDk5fQ.wG4i5gvxTG6Ts-6jfQp1ZdDtF6RysMh-WtXQYACBl74"
}

Support

I wrote this repo by using my free time. A little motivation and support helps me a lot. If you like this nifty hack you can support me by doing any (or all πŸ˜‰ ) of the following:

  • ⭐ Star it on Github and make it trend so that other people can know about our project.
  • πŸ‘ Clap for the series of article on Medium
  • Tweet about it
  • Share this on Facebook

About

Backend for a To-Do application. This is part of series of medium article that I wrote.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published
0