
Product
Introducing Tier 1 Reachability: Precision CVE Triage for Enterprise Teams
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.
todo-api-jwt
Advanced tools
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)
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.
Installing node.js
brew install node
sudo apt-get install nodejs npm
https://nodejs.org/
git clone https://github.com/vreymond/Todo-List-API.git
npm install
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.
All the routes have been tested using the Insomnia program.
You can access the API by using the URL http://localhost:<portAPI>/
(default port is 3000).
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"
}
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:
http://localhost:3000/lists/new?name=todo-test
The API will respond:
{
"id": 1,
"name": "todo-test",
"nb_tasks": 0
}
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
}
]
http://localhost:3000/list/{id-todo}/new-task?name=task1
The API will respond:
{
"id": 1,
"name": "task1",
"status": "todo"
}
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"
}
http://localhost:3000/list/{id-list}/tasks
The API will respond:
[
{
"id": 1,
"name": "task1",
"status": "done"
}
]
http://localhost:3000/list/{id-list}/delete-task?task_id=1
The API will respond:
{
"message": "Task id: 1 correctly deleted"
}
Valentin Reymond
This project is licensed under the MIT License - see the LICENSE file for details
FAQs
API that manages to do lists for users
The npm package todo-api-jwt receives a total of 3 weekly downloads. As such, todo-api-jwt popularity was classified as not popular.
We found that todo-api-jwt demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.
Research
/Security News
Ongoing npm supply chain attack spreads to DuckDB: multiple packages compromised with the same wallet-drainer malware.
Security News
The MCP Steering Committee has launched the official MCP Registry in preview, a central hub for discovering and publishing MCP servers.