Skip to content

alexoleynik0/oa-nodejs-internship-lesson3-express-pt1

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

oa-nodejs-internship-lesson3-express-pt1

Simple Express.js REST API with faux (fake) DB.

Basic Usage

Start server

npm install
node index.js

Test any of the /v1/user REST endpoints:

# get all users
curl -X GET 'localhost:3000/v1/user'

# get user by ID
curl -X GET 'localhost:3000/v1/user/1'

# create user
curl -X POST 'localhost:3000/v1/user' -H 'Content-Type: application/json' -d '{"name": "test user", "email": "test@email.com"}'

# put user by ID
curl -X PUT 'localhost:3000/v1/user/1' -H 'Content-Type: application/json' -d '{"name": "put user", "email": "put@email.com"}'

# patch user by ID
curl -X PATCH 'localhost:3000/v1/user/1' -H 'Content-Type: application/json' -d '{"name": "patch user"}'

# delete user by ID
curl -X DELETE 'localhost:3000/v1/user/1'

Additional tests (optional)

Check request body validation (Joi is used):

# cause validation error (see src/components/user/schemas@userCreateSchema)
curl -X POST 'localhost:3000/v1/user' -H 'Content-Type: application/json' -d '{"email": "not@valid"}'

Check DB "email" unique index:

# cause DB error (see src/db/model@checkIndexes)
# replace "email" in the body with any value you already have in the faux DB users list
curl -X POST 'localhost:3000/v1/user' -H 'Content-Type: application/json' -d '{"name": "test", "email": "stepan@test.com"}'

Check 404 Resource Not Found:

# works for every ID-based request
# replace `999` with any ID that you don't have
curl -X GET 'localhost:3000/v1/user/999'

Check 404 Route Not Found:

curl -X GET 'localhost:3000/v1/user/first'

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published