Clone the repository, navigate to the project's folder:
git clone https://github.com/4unkur/simple-crud-api.git
cd simple-crud-api
Install the dependencies
npm i
Copy the environment file:
cp .env.example .env
By default port 3000 is set. You can change it in the .env file
In order to run the application in development mode you can run
npm run start:dev
It will utilize nodemon under the hood
In order to run the application in production mode you can run
npm run start:prod
It will build the application in the build
directory and run the application
The API has several endpoints:
API path /person
:
- GET
/person
or/person/${personId}
will return all persons or person with correspondingpersonId
- POST
/person
is used to create record about new person and store it in database - PUT
/person/${personId}
is used to update record about existing person - DELETE
/person/${personId}
is used to delete record about existing person from database
Persons are stored as objects
that have following properties:
id
— unique identifier (string
,uuid
) generated on server sidename
— person's name (string
, required)age
— person's age (number
, required)hobbies
— person's hobbies (array
ofstrings
or emptyarray
, required)
API is RESTful by design, so it will return corresponding http status codes:
200
- OK201
- Created204
- No-Content400
- Bad Request404
- Not Found500
- Server Error
Example Requests using Postman
Create a person: Fetching a person by id:
In order to run the test just run
npm run test
No need to boot up the server to perform end-to-end testing. It will boot up the server itself