rrezartprebreza/spring-boot-skills / skills/spring-boot-3/hateoas
hateoas
VerifiedUse when adding hypermedia links to REST responses, building self-describing APIs, or implementing Spring HATEOAS. Use when you see EntityModel, CollectionModel, or RepresentationModel in the project.
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 5.7 KB |
| agents/openai.yaml | config | 182 B |
| examples/bad-hateoas-controller.java | other | 1.6 KB |
| examples/good-hateoas-controller.java | other | 2.0 KB |
| templates/OrderModelAssembler.java | other | 1.9 KB |
templates/OrderModelAssembler.java
View on GitHubpackage com.example.order.controller;
import com.example.order.dto.response.OrderResponse;
import com.example.order.entity.Order;
import com.example.order.entity.OrderStatus;
import org.springframework.hateoas.EntityModel;
import org.springframework.hateoas.server.RepresentationModelAssembler;
import org.springframework.lang.NonNull;
import org.springframework.stereotype.Component;
import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.linkTo;
import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.methodOn;
@Component
public class OrderModelAssembler
implements RepresentationModelAssembler<Order, EntityModel<OrderResponse>> {
@Override
@NonNull
public EntityModel<OrderResponse> toModel(@NonNull Order order) {
EntityModel<OrderResponse> model = EntityModel.of(
OrderResponse.from(order),
// Self link — always present
linkTo(methodOn(OrderController.class).getById(order.getId())).withSelfRel(),
// Collection link
linkTo(methodOn(OrderController.class).list(null, null)).withRel("orders"));
// Conditional action links based on current state
OrderStatus status = order.getStatus();
if (status == OrderStatus.PENDING) {
model.add(linkTo(methodOn(OrderController.class)
.confirm(order.getId())).withRel("confirm"));
model.add(linkTo(methodOn(OrderController.class)
.cancel(order.getId())).withRel("cancel"));
}
if (status == OrderStatus.CONFIRMED) {
model.add(linkTo(methodOn(OrderController.class)
.ship(order.getId())).withRel("ship"));
}
if (status == OrderStatus.SHIPPED) {
model.add(linkTo(methodOn(OrderController.class)
.deliver(order.getId())).withRel("deliver"));
}
return model;
}
}
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| receiving-code-reviewobra/superpowersUse when receiving code review feedback, before implementing suggestions, especially if feedback seems unclear or technically questionable - requires technical rigor and verification, not performative agreement or blind implementation | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| requesting-code-reviewobra/superpowersUse when completing tasks, implementing major features, or before merging to verify work meets requirements | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| using-git-worktreesobra/superpowersUse when starting feature work that needs isolation from current workspace or before executing implementation plans - ensures an isolated workspace exists via native tools or git worktree fallback | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| verification-before-completionobra/superpowersUse when about to claim work is complete, fixed, or passing, before committing or creating PRs - requires running verification commands and confirming output before making any success claims; evidence before assertions always | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |