CRUD Recap Project
This project is an app that renders services provided by users, and allows their editing, creation and removal.
API Endpoints
They are organised in two files:
/pages/api/services/index.js
: for the operations relative to the list of all services;/pages/api/services/[id].js
: for the operations relative to the single service.
Method | URL | What it does |
---|---|---|
GET | /api/services | Gets all services |
POST | /api/services | Creates new service |
GET | /api/services/:id | Gets service by id |
PUT | /api/services/:id | Edits service by id |
DELETE | /api/services/:id | Deletes service by id |
Pages
Paths are relative to the /pages
folder.
File | URL | What it does |
---|---|---|
index.js | / | Displays all services |
new.js | /new | Displays the create service form |
services/[id].js | /services/:id | Displays a service by given id |
services/edit/[id].js | /services/edit/:id | Displays the edit service form |
Development
Local Development
First provide the MongoDB connection URL in the .env.local
file:
MONGODB_URI=mongodb+srv://<USERNAME>:<PASSWORD>@cluster0.tdm0q.mongodb.net/<DBNAME>?retryWrites=true&w=majority
Then install the dependencies using npm i
.
Run npm run dev
to start a development server and open the displayed URL in a browser.
Use npm run db:populate
to fill the db with some initial data.
Scripts
You can use the following commands:
npm run dev
to start a development servernpm run build
to build the projectnpm run start
to start a production servernpm run test
to run the testsnpm run lint
to run the linternpm run db:populate
to populate the db with some fixtures