This is a simple CRUD (Create, Read, Update, Delete) API for a phonebook application. It's built with Node.js, Prisma, TypeScript, and SQLite. The API allows you to manage a list of contacts, where each contact has an id
, name
, and phone
data.
Before you start, ensure you have these installed on your system:
- Node.js and npm (Node Package Manager)
- TypeScript
- Prisma
- SQLite
To set up the project on your local machine:
- Clone the repository:
git clone https://github.com/yourusername/phonebook-api.git
cd phonebook-api
- Install the dependencies:
npm install
- Generate the Prisma client:
npx prisma generate
- Run the API:
npx ts-node index.ts
Your API should now be running on http://localhost:3000.
Here are some examples of how you can use the API:
- Create a new contact:
curl -X POST -H "Content-Type: application/json" -d '{"name":"John Doe", "phone":"1234567890"}' http://localhost:3000/contacts
- Get all contacts:
curl http://localhost:3000/contacts
- Update a contact:
curl -X PUT -H "Content-Type: application/json" -d '{"name":"Jane Doe", "phone":"0987654321"}' http://localhost:3000/contacts/1
- Delete a contact:
curl -X DELETE http://localhost:3000/contacts/1