This is a basic Express server that provides an API for managing contacts.
- Simple API for adding, deleting, and retrieving contacts
- Uses
dotenvto load environment variables from a.envfile - Supports CORS for cross-origin requests
- Node.js (v12 or higher)
- npm (v6 or higher)
-
Clone the repository:
(https://github.com/Herobiam/contactserver.git) cd contactserver
2. **Install dependencies**:
```bash
npm install
-
Create a
.envfile in the root directory:ORIGIN=http://localhost:3000 -
Run the server:
npm start
By default, the server will run on the port specified in the
.envfile (e.g.,http://localhost:3000).
Retrieves the list of contacts for the user identified by the Authorization header.
Example request:
curl -H "Authorization: your-token" http://localhost:3000/contactsAdds a new contact for the user.
Request body (JSON):
{
name: 'First National Bank',
surname: 'Bank',
email: 'contact@fnb.com',
},Example request:
curl -X POST -H "Content-Type: application/json" -H "Authorization: your-token" -d '{"name": "John Doe", "surname": "mkafa", "email": "makafa@d.com"}' http://localhost:3000/contactsDeletes a contact by its id.
Example request:
curl -X DELETE -H "Authorization: your-token" http://localhost:3000/contacts/contact-idThis project is licensed under the MIT License.