Skip to content

Karunya-B/Contacts-version-api

Repository files navigation

Contacts API

A RESTful API for managing contacts with user authentication built using Node.js, Express, and MongoDB.

🚀 Live Demo

API is deployed at: https://contacts-version-api-2.onrender.com

✨ Features

  • User authentication with JWT
  • CRUD operations for contacts
  • Input validation
  • Error handling
  • MongoDB database integration
  • Environment configuration

🛠️ Technology Stack

  • Node.js
  • Express.js
  • MongoDB
  • JWT Authentication
  • Express-Async-Handler
  • Bcrypt

📝 API Endpoints

User Routes

Method Endpoint Description
POST /api/users/register Register new user
POST /api/users/login Login user
GET /api/users/current Get current user info

Contact Routes

Method Endpoint Description
GET /api/contacts Get all contacts
POST /api/contacts Create new contact
GET /api/contacts/:id Get contact by ID
PUT /api/contacts/:id Update contact
DELETE /api/contacts/:id Delete contact

🚀 Installation

  1. Clone the repository:
git clone https://github.com/Karunya-B/Contacts-version-api.git
  1. Install dependencies:
cd Contacts-version-api
npm install
  1. Create .env file:
PORT=5000
MONGODB_URI=your_mongodb_connection_string
ACCESS_TOKEN_SECRET=your_jwt_secret
  1. Start the server:
# Development
npm run dev

# Production
npm start

🔑 Authentication

All contact routes require JWT token in Authorization header:

Authorization: Bearer your_jwt_token

📦 Example Usage

Register User

curl -X POST https://contacts-api-mk9f.onrender.com/api/users/register \
-H "Content-Type: application/json" \
-d '{"username":"test","email":"test@test.com","password":"password123"}'

Create Contact

curl -X POST https://contacts-api-mk9f.onrender.com/api/contacts \
-H "Content-Type: application/json" \
-H "Authorization: Bearer your_jwt_token" \
-d '{"name":"John Doe","email":"john@example.com","phone":"1234567890"}'

⚠️ Error Handling

The API uses consistent error response format:

{
  "title": "Error Type",
  "message": "Error details",
  "stackTrace": "Stack trace (development only)"
}

📄 License

MIT

👤 Author

Karunya B

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors