https://github.com/kwishna/expressjs-todo-list
Using Express JS To Create A Todo List APIs
https://github.com/kwishna/expressjs-todo-list
api expressjs javascript microservice nodejs
Last synced: 3 months ago
JSON representation
Using Express JS To Create A Todo List APIs
- Host: GitHub
- URL: https://github.com/kwishna/expressjs-todo-list
- Owner: kwishna
- Created: 2024-04-11T07:06:59.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-05-19T12:45:25.000Z (almost 2 years ago)
- Last Synced: 2024-12-28T20:21:42.886Z (about 1 year ago)
- Topics: api, expressjs, javascript, microservice, nodejs
- Language: JavaScript
- Homepage:
- Size: 1.18 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: Readme.MD
Awesome Lists containing this project
README
# Todo API
This is a simple RESTful API for managing todo lists. It allows users to create, read, update, and delete todo items.
## Getting Started
To get started with the Todo API, follow these instructions:
### Prerequisites
- Node.js installed on your machine
- SQLite database management system
### Installation
1. Clone the repository:
2. Navigate to the project directory:
3. Install dependencies:
4. Create a `.env` file in the project root and configure the environment variables:
5. Run the server:
## Usage
### Authentication
To use the API, you need to obtain an access token by authenticating with your username and password. Send a POST request to `/login` with your credentials in the request body. The API will respond with an access token, which you can use to authenticate subsequent requests by including it in the `Authorization` header as a Bearer token.
### Endpoints
- `POST /signup`: Register a new user.
- `POST /login`: Authenticate and obtain an access token.
- `GET /todos`: Retrieve all todo items for the authenticated user.
- `POST /todos`: Create a new todo item.
- `PUT /todos/:id`: Update an existing todo item.
- `DELETE /todos/:id`: Delete a todo item.
### Example Usage
1. POST /auth/signup - Sign up for a new account.
Example request body:
{
"username": "exampleUser",
"password": "examplePassword"
}
Curl example:
curl -X POST -H "Content-Type: application/json" -d '{"username":"exampleUser", "password":"examplePassword"}' http://localhost:3000/auth/signup
2. POST /auth/login - Log in to obtain access token.
Example request body:
{
"username": "exampleUser",
"password": "examplePassword"
}
Curl example:
curl -X POST -H "Content-Type: application/json" -d '{"username":"exampleUser", "password":"examplePassword"}' http://localhost:3000/auth/login
3. GET /todos/list - Get all TODOs for the authenticated user.
Curl example:
curl -X GET -H "Authorization: Bearer " http://localhost:3000/todos/list
4. POST /todos/create - Create a new TODO.
Example request body:
{
"task": "Example task",
"completed": false
}
Curl example:
curl -X POST -H "Content-Type: application/json" -H "Authorization: Bearer " -d '{"task":"Example task", "completed":false}' http://localhost:3000/todos/create
5. PUT /todos/:id/update - Update a TODO by ID.
Example request body:
{
"task": "Updated task",
"completed": true
}
Curl example:
curl -X PUT -H "Content-Type: application/json" -H "Authorization: Bearer " -d '{"task":"Updated task", "completed":true}' http://localhost:3000/todos/1/update
6. DELETE /todos/:id/delete - Delete a TODO by ID.
Curl example:
curl -X DELETE -H "Authorization: Bearer " http://localhost:3000/todos/1/delete