FullstackDevZone is an approach to learning various programming languages and frameworks by building a sample application. This idea is heavily inspired by RealWorld.
DevZone is a web application where developers can register and post their favourite article/video as posts. To enable the application to be build using different programming languages and frameworks, the Backend and Frontend will be developed as separate applications in separate repositories.
- Users can register and login
- Authenticated user can create a new post
- Authenticated users can delete their own posts
- Admin user can delete any post
- Any user(including guest users) can view posts with pagination
- sort by posted date desc (default)
- by searching for a keyword
Assuming the backend API application is running on http://localhost:8080/ and there are two users exists with the following credentials:
- Admin: [email protected]/admin
- Normal User: [email protected]/siva
we can run smoke tests using the Postman collection as follows:
$ brew install newman //MacOS
$ npm install -g newman
$ newman run devzone-api.postman_collection.json
- URL:
POST /api/login
Request Payload:
{
"username": "[email protected]",
"password": "password"
}
Success Response:
{
"access_token": "jwt_token",
"expires_at": "expiry_timestamp",
"user": {
"id": 1,
"name": "user",
"email": "[email protected]",
"role": "ROLE_USER"
}
}
Example:
curl -X POST 'http://localhost:8080/api/login' \
-H 'Content-Type: application/json' \
-d '{
"username": "[email protected]",
"password": "admin"
}'
- URL:
POST /api/users
Request Payload:
{
"name": "sivaprasad",
"email": "[email protected]",
"password": "password"
}
curl -X POST 'http://localhost:8080/api/users' \
-H 'Content-Type: application/json' \
-d '{
"name":"newuser",
"email": "[email protected]",
"password": "secret"
}'
Success Response:
{
"id": 2,
"name": "newuser",
"email": "[email protected]",
"role": "ROLE_USER"
}
- URL:
POST /api/posts
Authorization: Bearer JWT_TOKEN_HERE
Request Payload:
{
"title": "post tile",
"url": "url",
"content": "content"
}
curl -X POST 'http://localhost:8080/api/posts' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer JWT_TOKEN_HERE' \
-d '{
"url": "https://sivalabs.in",
"title": "SivaLabs blog",
"content":"My experiments with technology"
}'
- URL:
GET /api/posts/:postId
Authorization: Bearer JWT_TOKEN_HERE
Success Response:
{
"id": 123,
"title": "post tile",
"url": "url",
"content": "content",
"createdBy": {
"id": 123,
"name": "siva"
},
"createdAt": "",
"updatedAt": ""
}
curl -X GET 'http://localhost:8080/api/posts/1'
- URL: DELETE /api/posts/:postId
- Authentication Required: true
curl -X DELETE 'http://localhost:8080/api/posts/1' \
-H 'Authorization: Bearer JWT_TOKEN_HERE'
- URL:
GET /api/posts?page=1&query=keyword
curl -X GET 'http://localhost:8080/api/posts?page=1' \
-H 'Content-Type: application/json'
Success Response:
{
"totalElements": 200,
"totalPages": 10,
"pageNumber": 1,
"isFirst": true,
"isLast": false,
"hasNext": true,
"hasPrevious": false,
"data": [
{
"id": 1,
"title": "post tile",
"url": "url",
"content": "content",
"createdBy": {
"id": 123,
"name": "siva"
}
},
{
"id": 2,
"title": "post tile",
"url": "url",
"content": "content",
"createdBy": {
"id": 456,
"name": "prasad"
}
}
]
}
- URL:
GET /api/me
- Authentication Required: true
Success Response:
{
"id": 1,
"name": "user",
"email": "[email protected]",
"role": "ROLE_ADMIN"
}
curl -X GET 'http://localhost:8080/api/me' \
-H 'Authorization: Bearer JWT_TOKEN_HERE'
- URL:
GET /api/users/:id
Success Response:
{
"id": 1,
"name": "user",
"email": "[email protected]",
"role": "ROLE_USER"
}
curl -X GET 'http://localhost:8080/api/users/1'
- Implement unit and integration tests
- Decent code coverage is nice to have
- Implement continuous integration CI using GitHub Actions or CircleCI etc