@jonreader/notes v1.8.0
Notes - Microservices Skill Test
Message for reviewer
Thanks for taking the time to review this test.
Whilst this app is a fully functioning API, some parts of the application are not as extensive as they would be in a real-world scenario (to avoid bloating the test).
The authentication middleware is mocked to function but does not use any external services. The unit tests (1 / 2) provide an example of working tests but are not application-wide.
Please note: To avoid convoluting this test the application requires a Mongodb database running locally on the default port of 27017 when developing or testing. You can run the application via docker to spin up a database if required (see below).
Semantic versioning
This repo makes use of both semantic commits and versioning.
Releases are automatically versioned via the commit messages using CI.
Running git commit
or npm run commit
will bring up an interactive commit helper in the console.
Run application (Docker)
- Clone the this repo
cd
into the repo directory- Run
docker-compose up
Spins up the node application and mongodb database. Runs port 80
.
Development
- Clone the this repo
cd
into the repo directory- Run
npm install
- Run
npm run dev
The application runs on a default port of 3000
when developing.
Testing
This application uses Jest to perform unit-testing and gather code coverage reports.
In a real-world scenario, this would be run per commit on release branches via CI.
- Clone the this repo
cd
into the repo directory- Run
npm test
API
Auth
The REST API requires an authorization Bearer token of 3.14159
.
This can be seen in the examples below.
Create
Route
URI | Verb | Description |
---|---|---|
/note | POST | Creates a note for a user |
Data
Property | Type | Required | Description |
---|---|---|---|
title | string | true | Note title |
description | string | true | Note description |
owner | string | true | UUID of note owner |
Example request:
curl \
--location --request POST 'http://0.0.0.0/note' \
--header 'Authorization: Bearer 3.14159' \
--header 'Content-Type: application/json' \
--data-raw '{
"title": "Feed dog",
"description": "Must remember to feed dog his food",
"owner": "facb1e6d-381f-445d-ab72-46559f8adb24"
}'
Example response:
{
"message": "OK",
"status": 200
}
Update
Route
URI | Verb | Description |
---|---|---|
/note/{noteid} | PATCH | Updates an existing note |
Data
Property | Type | Required | Description |
---|---|---|---|
title | string | optional | Note title update |
description | string | optional | Note description update |
Example request:
curl \
--location --request PATCH '0.0.0.0/note/{noteid}' \
--header 'Authorization: Bearer 3.14159' \
--header 'Content-Type: application/json' \
--data-raw '{"title":"Feed cat"}'
Example response:
{
"message": "OK",
"status": 200
}
List
Route
URI | Verb | Description |
---|---|---|
/note/{userid} | GET | Lists all notes belonging to an user |
Example request:
curl \
--location --request GET 'http://0.0.0.0/note/{userid}' \
--header 'Authorization: Bearer 3.14159'
Example successful response:
{
"message": "OK",
"status": 200,
"data": [
{
"_id": "612a42c1417683c61561b7dc",
"title": "Feed cat",
"description": "Must remember to feed cat her food",
"owner": "facb1e6d-381f-445d-ab72-46559f8adb24",
"created": 1630159553538,
"updated": 1630160984723
},
{
"_id": "612a4070417683c61561b7db",
"title": "Feed dog",
"description": "Must remember to feed dog his food",
"owner": "facb1e6d-381f-445d-ab72-46559f8adb24",
"created": 1630158960406,
"updated": 1630158960406
}
]
}
Example failure response
{
"message": "Note with id {noteid} not found.",
"status": 404
}
Delete
Route
URI | Verb | Description |
---|---|---|
/note/{noteid} | DELETE | Deletes an existing note |
Example request:
curl \
--location --request DELETE '0.0.0.0/note/{noteid}' \
--header 'Authorization: Bearer 3.14159'
Example successful response:
{
"message": "OK",
"status": 200
}
Example failure response:
{
"message": "Note with id {noteid} not found.",
"status": 404
}