A RESTful API built with Node.js and Express, designed to manage contact records through full CRUD (Create, Read, Update, Delete) operations.
- Node.js – JavaScript runtime environment for backend development
- Express.js – Minimal and flexible Node.js web application framework
- PostgreSQL – Relational database used to persist contact data
- Knex.js – SQL query builder for PostgreSQL
- Joi – Data validation for incoming requests
- Cors – Middleware to enable Cross-Origin Resource Sharing
- Dotenv – Environment variable management
- ✅ Create contacts with name, email, and phone
- ✅ Retrieve all contacts
- ✅ Get contact by ID
- ✅ Update contact information
- ✅ Delete contacts
- ✅ Validate data before insertion
-
Clone the repository:
git clone https://github.com/sampaiogabriel/api-my-contacts.git cd api-my-contacts -
Install dependencies:
npm install
-
Configure your environment variables (
.env):DATABASE_URL=postgres://user:password@localhost:5432/mycontacts
-
Run database migrations:
npx knex migrate:latest
-
Start the server:
npm start
-
API available at:
http://localhost:3000
- POST
/contacts - Request Body:
{ "name": "John Doe", "email": "john@email.com", "phone": "(11) 99999-9999" } - Response:
{ "id": 1, "name": "John Doe", "email": "john@email.com", "phone": "(11) 99999-9999" }
- GET
/contacts
- GET
/contacts/:id
- PUT
/contacts/:id - Request Body: (only include fields to be updated)
{ "name": "John P. Doe" }
- DELETE
/contacts/:id
This project is licensed under the MIT License.