npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

todo-api-jwt

v1.3.0

Published

API that manages to do lists for users

Downloads

7

Readme

Todo List API

NodeJs Javascript Mysql

This program is a REST API that allows clients to create to-do lists with tasks stored in a SQL database. This API is using the express architecture and a MySQL server. Clients can access the API with a token system by using the jsonwebtoken (JWT) npm module.

MAMP server have been used for the database developpement and Insomnia program for the client part (routes)

Getting Started

Prerequisites

  1. Launch a SQL server of your choice on your local or distant machine (like MAMP) and get the adress (host and port), username and password of this server.

  2. Installing node.js

  • Mac (homebrew):
brew install node
  • Linux (packet manager):
sudo apt-get install nodejs npm
  • Node website:
https://nodejs.org/

Installing

  1. Clone the repository project in the directory of your choice with:
git clone https://github.com/vreymond/Todo-List-API.git
  1. Move to the project directory, and install all npm modules dependencies needed by the program
npm install

Program launch

  • Start the SQL server

  • To access the helping manual of the Api containing the entire options list, use the following command:

node src/api.js -h 

You will get:

> Usage: api [options]

Options:
  -V, --version                output the version number
  -p, --portAPI <portAPI>      Set API port listening
  -P, --portDB <portDB>        Set DB port
  -d, --dbHost <dbHost>        Set Hostname for the mysql DB
  -u, --dbUser <userDBName>    Set DB username
  -w, --password <passwordDB>  Set DB password
  -l, --loglevel <logLevel     Set log level
  -h, --help                   output usage information

The -l (or --loglevel) option allows you to modify the verbosity of the console logs. To see debug level just use the following command:

node src/api.js -l debug

Ensure you start the API with the correct pool of options. Set your SQL server logs with options, like:

node src/api.js -P 8080 -d <server hostname> -u <db server user> -w <password server> 

If no options given, the MAMP (or another server) SQL server default logs will be used.

The program will create a database named "TodoProject" into the SQL server. This database include 3 tables (User, List and Tasks). When those 3 tables are created, a dummy user is inserted into the user table for testing.

API usage

All the routes have been tested using the Insomnia program.

1°) API index

You can access the API by using the URL http://localhost:<portAPI>/ (default port is 3000).

2°) API Login check route

First of all, to check his logins the client has to use the following route:

http://localhost:3000/login_check
// The posted data must be in a JSON format and contains only the "username" and "password" keys:

{
	"username": "test",
	"password": "1234"
}

The API server will return a token to the client (generated with the JWT module):

{
	"token":
		"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6InRlc3QiLCJwYXNzd29yZCI6IjEyMzQi
		CJpYXQiOjE1NTY0NTc2NTR9.pm3udoXwLGhaGzTtR_SaE8N1Ep75EAYWijz6i4jAEiE"
}

3°) Manage your todo list and tasks

Once the token is generated, it needs to put it on each header of future API requests. The header name key is "bearer" and the value start by "Bearer" followed by the JWT token:

// Request Header:
key: "bearer"
value: "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6InRlc3QiLCJwYXNzd29yZCI6IjEyMzQi
		CJpYXQiOjE1NTY0NTc2NTR9.pm3udoXwLGhaGzTtR_SaE8N1Ep75EAYWijz6i4jAEiE"

Just now the client can access the 6 following routes:

A - Lists routes

  • Creating new list:
http://localhost:3000/lists/new?name=todo-test

The API will respond:

{
  "id": 1,
  "name": "todo-test",
  "nb_tasks": 0
}
  • Show all lists stored in the database:
http://localhost:3000/lists/all

The API will return a JSON array of all todo lists created:

[
  {
    "id": 1,
    "name": "todo-test",
    "nb_tasks": 0
  }
]

B - Tasks routes

  • Create new task into a todo list:
http://localhost:3000/list/{id-todo}/new-task?name=task1

The API will respond:

{
  "id": 1,
  "name": "task1",
  "status": "todo"
}
  • Update task status

Once created, the task is marked as "todo" statement. There are only two statements for a task: "todo" or "done". If the client wants to update the task status, he uses the following route:

http://localhost:3000/list/{id-list}/update-task?task_id=1&status=done

The API will respond:

{
  "id": "1",
  "name": "task1",
  "status": "done"
}
  • Show all tasks in a todo list:
http://localhost:3000/list/{id-list}/tasks

The API will respond:

[
  {
    "id": 1,
    "name": "task1",
    "status": "done"
  }
]
  • Delete a task from a list
http://localhost:3000/list/{id-list}/delete-task?task_id=1

The API will respond:

{
  "message": "Task id: 1 correctly deleted"
}

Contributors

Valentin Reymond

Todo List API

github.com/vreymond

License

This project is licensed under the MIT License - see the LICENSE file for details