Skip to content

sampaiogabriel/api-my-contacts

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

📞 API My Contacts

A RESTful API built with Node.js and Express, designed to manage contact records through full CRUD (Create, Read, Update, Delete) operations.

🚀 Tech Stack

  • 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

📌 Features

  • ✅ Create contacts with name, email, and phone
  • ✅ Retrieve all contacts
  • ✅ Get contact by ID
  • ✅ Update contact information
  • ✅ Delete contacts
  • ✅ Validate data before insertion

🔧 Getting Started

  1. Clone the repository:

    git clone https://github.com/sampaiogabriel/api-my-contacts.git
    cd api-my-contacts
  2. Install dependencies:

    npm install
  3. Configure your environment variables (.env):

    DATABASE_URL=postgres://user:password@localhost:5432/mycontacts
  4. Run database migrations:

    npx knex migrate:latest
  5. Start the server:

    npm start
  6. API available at:

    http://localhost:3000
    

📖 API Endpoints

🔹 Create a Contact

  • 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"
    }

🔹 List All Contacts

  • GET /contacts

🔹 Get Contact by ID

  • GET /contacts/:id

🔹 Update Contact

  • PUT /contacts/:id
  • Request Body: (only include fields to be updated)
    {
      "name": "John P. Doe"
    }

🔹 Delete Contact

  • DELETE /contacts/:id

📝 License

This project is licensed under the MIT License.

About

A RESTful API built with Node.js and Express to manage contacts, enabling operations such as create, read, update, and delete (CRUD).

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors