2. Technologies
● Spring Boot
● Spring MVC
● Spring Data
● Spring Security
● Liquibase
● Maven
● Swagger
● Junit 4
● Mockito
● RestAssured
● Postgresql
● H2 – embeded for test
5. Rest main principals
● Client-Server with one API. Client and Server
are two separated applications!!!
● Stateless – session on client side, all required
info in url.
● Client can put to cash information from server
6. Main rest request
● GET – doesn't change resource
● PUT – (create, replace, update)you can make it
many times without creating duplicates
● POST - (The POST operation is very generic
and no specific meaning can be attached to it)
create something new
● Delete – simple delete
8. Repositories
● No more same jpql!
● No more DAO!
Methods from the box:
- save
- findOne
- exists
- findAll
- count
- delete
- deleteAll
https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#repository-query-keywords
9. Old good @Entity
@Entity
public class Person{
@Id
@Column(name = "person_id", nullable = false)
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(nullable = false, length = 30)
private String login;
@Column(nullable = false, length = 30)
private String password;
@Column(nullable = false, length = 30)
private String name;
@Column(nullable = false)
@Enumerated(EnumType.STRING)
private UserRoleEnum role;
}
public enum UserRoleEnum {
MODERATOR,
USER
}
10. First controller
● @RestController
● @RequestMapping("/api/person")
● public class PersonController {
●
● @RequestMapping(method = RequestMethod.GET)
● public List<Person> getPersons(){
● …...........................
● }
● }
20. Quick Annotation Overview
@Api Marks a class as a Swagger resource.
● @ApiImplicitParam Represents a single parameter in an API Operation.
● @ApiImplicitParams A wrapper to allow a list of multiple ApiImplicitParam objects.
● @ApiModel Provides additional information about Swagger models.
● @ApiModelPropertyAdds and manipulates data of a model property.
● @ApiOperation Describes an operation or typically a HTTP method against a specific path.
● @ApiParam Adds additional meta-data for operation parameters.
● @ApiResponse Describes a possible response of an operation.
● @ApiResponses A wrapper to allow a list of multiple ApiResponse objects.
● @Authorization Declares an authorization scheme to be used on a resource or an operation.
● @AuthorizationScope Describes an OAuth2 authorization scope.
● @ResponseHeader Represents a header that can be provided as part of the response.