This is a simple API to run a simple Todo list backend, it uses Redis as a database an a Node.js server to handle the request.
You must have installed docker to run this application.
The backend API is a simple Express.js application with Redis as a database, code is stored in the server
folder.
To run it you will need docker, once docker is installed just run the following command:
# Running in background
docker-compose up -d
# Or in verbose mode
docker-compose up
To stop the backend API simply run docker-compose down
.
server
: the backend API available athttp://localhost:7878
redis
: Redis database available atredis://localhost:6379
redis-commander
: A Redis web GUI to view the data in the Redis container, available athttp://localhost:8081
These are the endpoints you can call via REST requests:
GET /todo
- returns the todo listPOST /todo
- Add a new task to the todo listcurl --location --request POST 'localhost:7878/todo' \ --header 'Content-Type: application/json' \ --data-raw '{ "task": "hello world" }'
DELETE /todo
- Delete a task from the todo listcurl --location --request DELETE 'localhost:7878/todo/' \ --header 'Content-Type: application/json' \ --data-raw '{ "task": "hello world" }'
The same functionalities are available via a GraphQL endpoint which is accessible from http://localhost:7878/graphql.
Fetching todo list
query {
todo
}
Which outputs:
{
"data": {
"todo": [
"hello",
"helloWorld"
]
}
}
Adding a task
Variables:
{
"task": "hello steve"
}
Mutation:
mutation AddTask($task: String){
addTask(task: $task) {
todo
}
}
Output:
{
"data": {
"addTask": {
"todo": [
"hello",
"helloWorld",
"hello steve"
]
}
}
}
Delete a task
Variables:
{
"task": "hello steve"
}
Mutation:
mutation DeleteTask($task: String){
deleteTask(task: $task) {
todo
}
}
Output:
{
"data": {
"deleteTask": {
"todo": [
"hello",
"helloWorld"
]
}
}
}