Skip to content

Latest commit

 

History

History
99 lines (94 loc) · 2.39 KB

README.md

File metadata and controls

99 lines (94 loc) · 2.39 KB

Express CRUD demo

A demonstration of CRUD operations with Express and Prisma

Open issues Github stars Total forks Github license

How to run in local environment

  • 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 the DATABASE_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

Available endpoints

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

Data schemas

Request
{
  "title": string,
  "completed": boolean
}
Response
{
  "success": boolean,
  "data": {
    "id": string,
    "title": string,
    "completed": boolean,
    "created": string,
  }
}

Notes

# 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 🔗