https://github.com/lizhanmit/spring-boot-rest-api-example
An example of using Spring Boot to build REST API.
https://github.com/lizhanmit/spring-boot-rest-api-example
java rest-api spring-boot
Last synced: 3 months ago
JSON representation
An example of using Spring Boot to build REST API.
- Host: GitHub
- URL: https://github.com/lizhanmit/spring-boot-rest-api-example
- Owner: lizhanmit
- Created: 2025-01-26T11:57:25.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2025-01-27T06:11:52.000Z (over 1 year ago)
- Last Synced: 2025-01-27T07:20:45.526Z (over 1 year ago)
- Topics: java, rest-api, spring-boot
- Language: Java
- Homepage:
- Size: 8.79 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# spring-boot-rest-api-example
This is an example of using Spring Boot to build REST API.
Swagger UI: http://localhost:8080/swagger-ui/index.html
OpenAPI specification: http://localhost:8080/v3/api-docs
## Data Transfer Object (DTO)
A DTO is an object that carries data between processes. DTOs are used to transfer data between the client and the server, or between different layers of the application. They help in decoupling the internal representation of data from the data that is exposed through the API, providing more flexibility and security.
By using DTOs, you can control the data that is exposed through the API, hide sensitive information, and change the internal representation of data without affecting the API contract.
## Pagination
Pagination is used to limit the size of returned result of getting all books.
The maximum page size is enforced to avoid performance issues and protect server from abuse.
## Test the API
GET: http://localhost:8080/api/books
GET: http://localhost:8080/api/books?page=0&size=10&sort=title,asc
POST: http://localhost:8080/api/books
```
{
"title": "dummy book",
"author": "dummy author",
"isbn": "111"
}
```
GET: http://localhost:8080/api/books/1
PUT: http://localhost:8080/api/books/1
```
{
"title": "dummy book",
"author": "dummy author",
"isbn": "222"
}
```
DELETE: http://localhost:8080/api/books/1