Implement simple CRUD API using in-memory database underneath.
$ git clone https://github.com/shopot/node-crud-api.git
$ cd node-crud-api
$ git checkout develop
$ npm install
Rename the file .env.example
to .env
for set load and set PORT environment variable from .env
file.
Start development server:
$ npm run start:dev
Build and start production server:
$ npm run start:prod
Start development server with Cluster API and balancing:
$ npm run start:dev:multi
Build and start production server with Cluster API and balancing:
$ npm run start:prod:multi
Run end-to-end (e2e) API test:
You must stop all production or development server before run tests
$ npm run test
https://nodejs-crud-openapi.netlify.app/
- GET
api/users
is used to get all persons- Response:
status code
200 and all users records
- Response:
- GET
api/users/${userId}
- Response:
status code
200 and and record withid === userId
if it exists - Response:
status code
400 and messageInvalid user id
if provided id is not valid uuid - Response:
status code
404 and messageUser not found
- Response:
- POST
api/users
is used to create record about new user and store it in database- Response:
status code
201 and newly created record - Response:
status code
400 and messageBad request
if requestbody
does not contain required fields
- Response:
- PUT
api/users/{userId}
is used to update existing user- Response:
status code
200 and updated record - Response:
status code
400 and messageInvalid user id
if provided id is not valid uuid - Response:
status code
404 and and messageUser not found
- Response:
- DELETE
api/users/${userId}
is used to delete existing user from database- Response:
status code
204 if the record is found and deleted - Response:
status code
400 and messageInvalid user id
if provided id is not valid uuid - Response:
status code
404 and and messageUser not found
- Response:
Requests to non-existing endpoints (e.g. some-non/existing/resource
) Response: status code
404 Not found
)
Script npm run test
runs end-to-end test for all HTTP Request (GET, CREATE, PUT, DELETE) methods with valid and invalid data.