Chapter 12 - HATEOAS and REST in Spring Boot

0.0(0)
studied byStudied by 4 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/21

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

22 Terms

1
New cards

What does HATEOAS stand for?

Hypermedia As The Engine Of Application State.

2
New cards

What is the purpose of HATEOAS in REST APIs?

It’s a principle in REST APIs where a Client doesn’t need to know everything upfront. Instead, it can discover what actions are available by following hyperlinks.

To allow clients to discover actions and resources via hyperlinks without hardcoding URIs.

3
New cards

What is HAL in the context of HATEOAS?

HAL (Hypertext Application Language) is a standard for adding hyperlinks to your JSON data.

It’s a way to make HATEOAS practical using JSON

4
New cards

What is a “self” link in HAL?

A link pointing to the current resource, useful for bookmarking or navigation.

5
New cards

Which HTTP method is used in Spring Boot to return HAL links?

GET (Spring Boot does not use OPTIONS for HATEOAS discovery).

6
New cards

how do you make a class capable of holding HAL links in Spring Boot?

Extend RepresentationModel<T>.

7
New cards

What method is used to add links to a model object?

add(...) from RepresentationModel.

8
New cards

What is the function of linkTo(...).withSelfRel()?

It creates a “self” link pointing to the current resource’s URL.

9
New cards

What is the purpose of the @JsonProperty annotation in Jackson?

To map a Java field/method to a JSON property with a different name.

10
New cards

What does HAL use to structure lists of related objects?

The _embedded property.

11
New cards

What does the CollectionModel<T> class do in Spring HATEOAS?

It wraps a collection of objects and allows links to be added to the collection itself.

12
New cards

In HAL+JSON, what is _links used for?

It contains all the hypermedia links associated with a resource.

13
New cards

How can you delete or edit a resource using HAL+JSON?

By sending a DELETE or PUT request to the URI in its self link.

14
New cards

What are the two main client options for handling HAL+JSON?

1. Parse as raw JSON using JsonNode
2. Map to Java classes with Jackson

15
New cards

What does objectMapper.readTree(...) do?

Parses a JSON string into a JsonNode tree structure.

16
New cards

What does the getDataItems(JsonNode) method do?

Recursively walks a JSON tree and prints all values.

17
New cards

How do you pretty-print a JsonNode with Jackson?

Use objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(node).

18
New cards

What does the getData(...) method in the client do?

Sends an HTTP GET request and returns the JSON response as a string.

19
New cards

What Spring Boot dependency is required to use RepresentationModel and HAL?

spring-hateoas

20
New cards

What is the content type of HAL+JSON responses?

application/hal+json

21
New cards

What is the purpose of the new link in a HAL response?

It indicates where a new resource (e.g., planet or moon) can be created via POST.

22
New cards

What’s the benefit of using HATEOAS over hardcoded URIs in clients?

It makes the client loosely coupled to the API and more adaptable to changes.