-
Make sure you have NodeJS v14 and npm installed.
-
Install your dependencies
cd path/to/sample-post npm install
-
Start your app
npm start
Simply run npm test
and all tests in the test/
directory will be run.
An example of initial mock data can be found in /src/init => InitialUsers()
This creates 2 users if not yet existing
POST http://localhost:3030/users
{
"email": "[email protected]",
"name": "Monkey D. Luffy",
"password": "password"
}
POST http://localhost:3030/authentication
{
"email": "[email protected]",
"password": "password",
"strategy": "local"
}
This will result to something like this
{
"accessToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6ImFjY2VzcyJ9.eyJpYXQiOjE2MTM2NTk1MzgsImV4cCI6MTYxMzc0NTkzOCwiYXVkIjoiaHR0cHM6Ly95b3VyZG9tYWluLmNvbSIsImlzcyI6ImZlYXRoZXJzIiwic3ViIjoiS25RNmJIMGd0Y1BlZ0lRcSIsImp0aSI6IjNmODRlMmMxLWNjN2EtNDI4ZS04OGNlLWZiZWEzNmIzZjcwOCJ9.MclegAuirlT53KcaLGfclm5LpFEkHLc0mEepW1yl1wM",
"authentication": {
"strategy": "local",
"accessToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6ImFjY2VzcyJ9.eyJpYXQiOjE2MTM2NTk1MzgsImV4cCI6MTYxMzc0NTkzOCwiYXVkIjoiaHR0cHM6Ly95b3VyZG9tYWluLmNvbSIsImlzcyI6ImZlYXRoZXJzIiwic3ViIjoiS25RNmJIMGd0Y1BlZ0lRcSIsImp0aSI6IjNmODRlMmMxLWNjN2EtNDI4ZS04OGNlLWZiZWEzNmIzZjcwOCJ9.MclegAuirlT53KcaLGfclm5LpFEkHLc0mEepW1yl1wM",
"payload": {
"iat": 1613659538,
"exp": 1613745938,
"aud": "https://yourdomain.com",
"iss": "feathers",
"sub": "KnQ6bH0gtcPegIQq",
"jti": "3f84e2c1-cc7a-428e-88ce-fbea36b3f708"
}
},
"user": {
"email": "[email protected]",
"name": "Monkey D. Luffy",
"_id": "KnQ6bH0gtcPegIQq"
}
}
IMPORTANT is to get accessToken
as we will use this as authorization in header
Find and Get
of post doesn't require accessToken
Post, Patch, and Delete
requires access token
IMPORTANT: User is not allowed to modify/delete other user's post
POST http://localhost:3030/posts
headers.authorization = Bearer accessToken
{
"title": "Title",
"content": "New Content",
"image": "image link"
}
PATCH http://localhost:3030/posts/_id
headers.authorization = Bearer accessToken
{
"title": "New Title",
"content": "New New Content",
"image": "New image link"
}
DELETE http://localhost:3030/posts/_id
headers.authorization = Bearer accessToken