The My Contact Backend API is a robust and scalable Express.js application designed to manage contact information efficiently. This API provides a seamless interface for users to create, read, update, and delete contact records, ensuring a smooth user experience.
To set up the project locally, follow these steps:
-
Clone the repository:
git clone https://github.com/yourusername/mycontact-backend.git
-
Navigate to the project directory:
cd mycontact-backend
-
Install the dependencies:
npm install
-
Set up your environment variables:
Create a
.env
file in the root directory and add the following:CONNECTION_STRING=your_mongodb_connection_string
To start the server, run the following command:
npm start
The API will be accessible at http://localhost:5000
.
The following endpoints are available in the API:
- GET /api/contacts: Retrieve all contacts.
- POST /api/contacts: Create a new contact.
- GET /api/contacts/:id: Retrieve a specific contact by ID.
- PUT /api/contacts/:id: Update a specific contact by ID.
- DELETE /api/contacts/:id: Delete a specific contact by ID.
To create a new contact, send a POST request to /api/contacts
with the following JSON body:
{
"username": "John Doe",
"email": "john.doe@example.com"
}
A successful response will return the created contact object:
{
"id": "12345",
"username": "John Doe",
"email": "john.doe@example.com"
}
The API employs standardized error handling. In case of an error, the API will respond with a JSON object containing the error message and status code.
Contributions are welcome! If you would like to contribute to this project, please follow these steps:
- Fork the repository.
- Create a new branch for your feature or bug fix.
- Submit a pull request detailing your changes.
This project is licensed under the MIT License. See the LICENSE file for more details.