A Simple Blog App that allows users to create and manage blogs.
- Create, update, and delete blogs
- Get all blogs
- Get a blog by id
- Get all authors
- Get an author by id
- Register a new user
- Login a user
- Spring Boot
- Spring Security
- Spring Data JPA
- PostgreSQL
- Maven
- JWT
- Lombok
- Clone the repository
- Run
mvn clean package
- Run
java -jar target/blog-app-0.0.1-SNAPSHOT.jar
Register a new user
curl -X POST http://localhost:8080/api/auth/register
-H "Content-Type: application/json"
-d '{
"name": "user1",
"email": "t1@t.com",
"password": "password"
}'
Code | Description | Response Body |
---|---|---|
201 | Created | The user was successfully created |
id | String | Unique identifier for the user |
name | String | The name of the user |
String | The email of the user | |
imageUrl | String | The URL of the user's profile image |
Code | Description | Response Body |
---|---|---|
400 | Bad request | Invalid request body |
message | String | The error message |
Login a user with email and password
curl -X POST http://localhost:8080/api/auth/login
-H "Content-Type: application/json"
-d '{
"email": "t1@t.com",
"password": "password"
}'
Code | Description | Response Body |
---|---|---|
token | String | The access token |
Code | Description | Response Body |
---|---|---|
400 | Bad request | Invalid request body |
message | String | The error message |
Get the current user
curl -X GET http://localhost:8080/api/auth/user
-H "Content-Type: application/json"
-H "Authorization: Bearer YOUR_ACCESS_TOKEN"
Code | Description | Response Body |
---|---|---|
200 | OK | The user was successfully retrieved |
id | String | Unique identifier for the user |
name | String | The name of the user |
String | The email of the user | |
imageUrl | String | The URL of the user's profile image |
Code | Description | Response Body |
---|---|---|
400 | Bad request | Invalid request body |
message | String | The error message |
Update the current user's profile
curl -X PUT http://localhost:8080/api/auth/user/profile
-H "Content-Type: application/json"
-H "Authorization: Bearer YOUR_ACCESS_TOKEN"
-d '{
"name": "user1 updated",
"email": "t1@t.com",
"password": "password"
}'
Code | Description | Response Body |
---|---|---|
200 | OK | The user was successfully updated |
status | Integer | The status code |
message | String | The message |
Code | Description | Response Body |
---|---|---|
400 | Bad request | Invalid request body |
status | Integer | The status code |
message | String | The error message |
Get All blogs
curl -X GET http://localhost:8080/api/blogs
-H "Content-Type: application/json"
-H "Authorization: Bearer YOUR_ACCESS_TOKEN"
Response
[
{
"id": "b1",
"title": "blog1",
"content": "blog1 content",
"author": {
"id": "u1",
"name": "user1",
"email": "t1@t.com",
"imageUrl": "https://example.com/user1.jpg"
},
}
...
]
Field | Type | Description |
---|---|---|
id | String | Unique identifier for the blog |
title | String | The title of the blog |
content | String | The content of the blog |
author | Object | The author of the blog |
Respose Author
Field | Type | Description |
---|---|---|
id | String | Unique identifier for the author |
name | String | The name of the author |
String | The email of the author | |
imageUrl | String | The URL of the author's profile image |
Code | Description | Response Body |
---|---|---|
400 | Bad request | Invalid request body |
message | String | The error message |
Get a blog by id
curl -X GET http://localhost:8080/api/blogs/b1
-H "Content-Type: application/json"
-H "Authorization: Bearer YOUR_ACCESS_TOKEN"
Response
{
"id": "b1",
"title": "blog1",
"content": "blog1 content",
"author": {
"id": "u1",
"name": "user1",
"email": "t1@t.com",
"imageUrl": "https://example.com/user1.jpg"
}
}
Response Entity
Field | Type | Description |
---|---|---|
id | String | Unique identifier for the blog |
title | String | The title of the blog |
content | String | The content of the blog |
author | Object | The author of the blog |
Respose Author
Field | Type | Description |
---|---|---|
id | String | Unique identifier for the author |
name | String | The name of the author |
String | The email of the author | |
imageUrl | String | The URL of the author's profile image |
Code | Description | Response Body |
---|---|---|
400 | Bad request | Invalid request body |
message | String | The error message |
Create a new blog
curl -X POST http://localhost:8080/api/blogs
-H "Content-Type: application/json"
-H "Authorization: Bearer YOUR_ACCESS_TOKEN"
-d '{
"title": "blog1",
"content": "blog1 content"
}'
Code | Description | Response Body |
---|---|---|
201 | Created | The blog was successfully created |
id | String | Unique identifier for the blog |
title | String | The title of the blog |
content | String | The content of the blog |
author | Object | The author of the blog |
Respose Author
Field | Type | Description |
---|---|---|
id | String | Unique identifier for the author |
name | String | The name of the author |
String | The email of the author | |
imageUrl | String | The URL of the author's profile image |
Query Params
Field | Type | Description |
---|---|---|
page | Integer | The page number |
size | Integer | The number of items per page |
Code | Description | Response Body |
---|---|---|
400 | Bad request | Invalid request body |
message | String | The error message |
Update a blog by id
curl -X PUT http://localhost:8080/api/blogs/b1
-H "Content-Type: application/json"
-H "Authorization: Bearer YOUR_ACCESS_TOKEN"
-d '{
"title": "blog1 updated",
"content": "blog1 content updated"
}'
Code | Description | Response Body |
---|---|---|
200 | OK | The blog was successfully updated |
id | String | Unique identifier for the blog |
title | String | The title of the blog |
content | String | The content of the blog |
author | Object | The author of the blog |
Respose Author
Field | Type | Description |
---|---|---|
id | String | Unique identifier for the author |
name | String | The name of the author |
String | The email of the author | |
imageUrl | String | The URL of the author's profile image |
Code | Description | Response Body |
---|---|---|
400 | Bad request | Invalid request body |
message | String | The error message |
Delete a blog by id
curl -X DELETE http://localhost:8080/api/blogs/b1
-H "Content-Type: application/json"
-H "Authorization: Bearer YOUR_ACCESS_TOKEN"
Code | Description | Response Body |
---|---|---|
200 | OK | The blog was successfully deleted |
message | String | A success message |
Code | Description | Response Body |
---|---|---|
400 | Bad request | Invalid request body |
message | String | The error message |
Get all authors
curl -X GET http://localhost:8080/api/authors
-H "Content-Type: application/json"
-H "Authorization: Bearer YOUR_ACCESS_TOKEN"
Code | Description | Response Body |
---|---|---|
200 | OK | The authors were successfully retrieved |
authors | Array | An array of authors |
Respose Author
Field | Type | Description |
---|---|---|
id | String | Unique identifier for the author |
name | String | The name of the author |
String | The email of the author | |
imageUrl | String | The URL of the author's profile image |
Query Params
Field | Type | Description |
---|---|---|
page | Integer | The page number |
size | Integer | The number of items per page |
Code | Description | Response Body |
---|---|---|
400 | Bad request | Invalid request body |
message | String | The error message |
Get an author by id
curl -X GET http://localhost:8080/api/authors/u1
-H "Content-Type: application/json"
-H "Authorization: Bearer YOUR_ACCESS_TOKEN"
Code | Description | Response Body |
---|---|---|
200 | OK | The author was successfully retrieved |
author | Object | The author |
Respose Author
Field | Type | Description |
---|---|---|
id | String | Unique identifier for the author |
name | String | The name of the author |
String | The email of the author | |
imageUrl | String | The URL of the author's profile image |
Code | Description | Response Body |
---|---|---|
400 | Bad request | Invalid request body |
message | String | The error message |
Get all blogs by author id
curl -X GET http://localhost:8080/api/authors/u1/blogs
-H "Content-Type: application/json"
-H "Authorization: Bearer YOUR_ACCESS_TOKEN"
Code | Description | Response Body |
---|---|---|
200 | OK | The blogs were successfully retrieved |
blogs | Array | An array of blogs |
Respose Blog
Field | Type | Description |
---|---|---|
id | String | Unique identifier for the blog |
title | String | The title of the blog |
content | String | The content of the blog |
author | Object | The author of the blog |
Respose Author
Field | Type | Description |
---|---|---|
id | String | Unique identifier for the author |
name | String | The name of the author |
String | The email of the author | |
imageUrl | String | The URL of the author's profile image |
Query Params
Field | Type | Description |
---|---|---|
page | Integer | The page number |
size | Integer | The number of items per page |
Code | Description | Response Body |
---|---|---|
400 | Bad request | Invalid request body |
message | String | The error message |
Get an image by filename
curl -X GET http://localhost:8080/api/images/u1.png
-H "Content-Type: image/png"
Code | Description | Response Body |
---|---|---|
200 | OK | The image was successfully retrieved |
image | Object | The image |
Code | Description | Response Body |
---|---|---|
400 | Bad request | Invalid request body |
message | String | The error message |