Skip to content

Latest commit

 

History

History
69 lines (60 loc) · 2.17 KB

README.md

File metadata and controls

69 lines (60 loc) · 2.17 KB

RESTfull API Level 4

Still Under Development

HATEOAS * Semantic HTTP Verbs * Resources / URI * Caching * OAS / Swagger

You can run the application using Maven wrapper

$ ./mvnw clean spring-boot:run

Installed Maven

$ mvn clean spring-boot:run

Or using the 'Run' command of your IDE.

Example of a RESTfull Resquest/Response

GET Request:

http://{host}/employees/1

JSON Response:

{
  "id": 1,
  "name": "Bilbo Baggins",
  "role": "burglar",
  "_links": {
    "self": {
      "href": "http://localhost:8080/employees/1"
    },
    "employees": {
      "href": "http://localhost:8080/employees"
    }
  }
}

The interface ResourceAssembler, helps to implement HATEOAS using links and the HAL format.

@Component
public class EmployeeResourceAssembler implements ResourceAssembler<Employee, Resource<Employee>> {

    @Override
    public Resource<Employee> toResource(Employee employee) {
        return new Resource<Employee>(employee,
                linkTo(methodOn(EmployeeController.class).one(employee.getId())).withSelfRel(),
                linkTo(methodOn(EmployeeController.class).all()).withRel("employee")
        );
    }
}

Me:

References: