A demonstration of CRUD operations with Express
and Prisma
- Clone project
git clone https://github.com/dMaisnam/express-demo.git
- Go to project directory
cd express-demo
- Install dependencies
npm install
# If you use yarn
yarn install
- Create a file called
.env
in your project root and define theDATABASE_URL
below to the file
echo DATABASE_URL="file:./dev.db" > .env
- Apply migrations
npx prisma db pull
- Run server
# In development
npm run dev
# in production
npm run start
API_URL = http://127.0.0.1:3001
- GET
{{API_URL}}/api/v1/_check
- Check server status - GET
{{API_URL}}/api/v1/todos
- Get all todos - POST
{{API_URL}}/api/v1/todos
- Create new todo - GET
{{API_URL}}/api/v1/todos/:id
- Get todo by id - PUT
{{API_URL}}/api/v1/todos/:id
- Update todo by id - DELETE
{{API_URL}}/api/v1/todos/:id
- Delete todo by id
{
"title": string,
"completed": boolean
}
{
"success": boolean,
"data": {
"id": string,
"title": string,
"completed": boolean,
"created": string,
}
}
# Get all
curl http://127.0.0.1:3001/api/v1/todos
# Get by id
curl http://127.0.0.1:3001/api/v1/todos/:id
# Post
curl -X POST -H "Content-Type:application/json" --data "{\"title\": \"Your title\", \"completed\": false}" http://127.0.0.1:3001/api/v1/todos
# Put by id
curl -X PUT -H "Content-Type:application/json" --data "{\"title\": \"Your title updated\", \"completed\": true}" http://127.0.0.1:3001/api/v1/todos/:id
# Delete by id
curl -X DELETE http://127.0.0.1:3001/api/v1/todos/:id
Created by Deba Maisnam 🔗