GitHub - ImRi8/PhoneBook-API: This project is a Contact Management API built with Node.js, Express, and Sequelize (SQLite). It allows users to register, login, add contacts, mark numbers as spam, search for contacts, and retrieve user details.
# Contact Management API
This project is a Contact Management API built with Node.js, Express, and Sequelize (SQLite). It allows users to register, login, add contacts, mark numbers as spam, search for contacts, and retrieve user details.
## Project Setup
### Prerequisites
- Node.js and npm installed on your machine.
### Installation
1. **Install dependencies:**
```bash
npm install
```
2. **Start the server:**
```bash
npm start
```
The server will start on `http://localhost:3000`.
## API Endpoints
### User Registration
- **Endpoint:** `POST /api/register`
- **Request Body:**
```json
{
"name": "John Doe",
"phoneNumber": "1234567890",
"email": "john.doe@example.com",
"password": "securepassword"
}
```
### User Login
- **Endpoint:** `POST /api/login`
- **Request Body:**
```json
{
"phoneNumber": "1234567890",
"password": "securepassword"
}
```
### Add a Contact
- **Endpoint:** `POST /api/users/:userId/contacts`
- **Request Body:**
```json
{
"name": "Jane Smith",
"phoneNumber": "0987654321"
}
```
### Get All Contacts of a User
- **Endpoint:** `GET /api/users/:userId/contacts`
### Mark a Number as Spam
- **Endpoint:** `POST /api/spam`
- **Request Body:**
```json
{
"phoneNumber": "1122334455"
}
```
### Get Numbers as Spam
- **Endpoint:** `GET /api/spam`
### Search by Name
- **Endpoint:** `GET /api/search/name/:name`
### Search by Phone Number
- **Endpoint:** `GET /api/search/phone/:phoneNumber`
### Get details of a person
- **Endpoint:** `GET /api/person/:phoneNumber`
### Retrieve the contact list
- **Endpoint:** `GET /api/phonebook`
## Testing the API
Use Postman or a similar tool to test the API endpoints. Ensure the following steps:
1. **Register a user** using the registration endpoint.
2. **Login with the registered user** to receive an authentication token (cookie) which will automatically added to the header cookies.
3. **Add contacts** to the user.
4. **Retrieve the contact list** for the user.
5. **Mark numbers as spam.**
6. **Get numbers as spam.**
7. **Search for contacts** by name or phone number.
8. **Get details of a person** by their phone number where email would be shown only to those contact which are in logged in person's contact directory.
Ensure to include the authentication token (cookie) in the requests where required.