Chapter 10 - Parameter Passing and Good Practice in REST

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

1/59

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.

60 Terms

1
New cards

What is the main challenge in passing data in REST compared to SOAP?

REST gives you more flexibility but requires you to manually manage data formats and parameter passing, unlike SOAP which has automatic structuring.

2
New cards

How is data passed in SOAP?

Through structured XML in the request/response body, often including method names and typed parameters.

3
New cards

What does REST not assume about data?

REST does not assume any specific data format (e.g., XML, JSON), so you must define and manage it yourself.

4
New cards

Why can't we use plain text REST calls for complex operations?

Plain text doesn’t handle multiple or structured parameters well — it’s unclear how to interpret the data.

5
New cards

what does verbose mean?

using or containing more words than necessary

6
New cards

what are 3 major problems with REST?

  1. no support for operations that return results and accept arguments

  2. no way to distinguish multiple arguments from complex single values

  3. no built-in support for structured data

7
New cards

Difference between SOAP and REST, with topic categories:

  1. data format

  2. built-in method names

  3. structured data handling

  4. verbose

  5. easy for simple text

  6. easy for structured arguments

8
New cards

What are the main parameter types used in REST?

  1. Query - To filter/sort resources

  2. Form - form web forms via POST

  3. Path - to identify resources

  4. Header - for meta-info (e.g., tokens)

  5. (rarely) Matrix parameters.

9
New cards

What are query parameters?

Key-value pairs appended to the URL after a ?, e.g., ?colour=red.

10
New cards

Where are form parameters located?

In the body of a POST/PUT request, formatted as key=value&key2=value2.

11
New cards

What are path parameters?

Values embedded directly in the URI path, e.g., /fruit/red/apple.

12
New cards

What are header parameters used for?

Metadata like auth tokens or content type, passed in HTTP headers.

13
New cards

Are all MIME type + HTTP method + parameter combinations valid?

No. Some combinations are disallowed or considered bad practice — stick to common patterns.

14
New cards

Best practices for allowable combinations for paths

15
New cards

summary for REST tools to pass data

16
New cards

How do you bind query parameters in Spring Boot?

Using @RequestParam in your controller method.

17
New cards

How do you customize the query parameter name?

@RequestParam(name = "customName").

18
New cards

How do you make a query parameter optional?

Use @RequestParam(required = false).

19
New cards

How do you assign a default value to a query parameter?

@RequestParam(defaultValue = "default").

20
New cards

How do you collect all query parameters into a map?

@RequestParam Map<String, String> allParams.

21
New cards

How do you handle multiple values for one query parameter?

Use @RequestParam List<String> items and pass values like items=a,b,c.

22
New cards

How does a client send query parameters in Java?

By appending them to the URL:

java

new URI("http://.../path?x=5&y=7")

23
New cards

Where are form parameters sent?

In the body of a POST or PUT request, formatted as key=value.

24
New cards

What header must be set for Spring to treat parameters as form data?

Content-Type: application/x-www-form-urlencoded

25
New cards

What annotation is used in Spring Boot to read form parameters?

@RequestParam, same as for query parameters.

26
New cards

How many form parameters can you have?

As many as needed — just add more @RequestParam parameters.

27
New cards

How does a client send form parameters?

Include a formatted string in the body and set the correct header.

28
New cards

How are path parameters defined in Spring Boot?

Using curly braces in the mapping and @PathVariable.

29
New cards

Can parameter names in the URI differ from variable names in Java?

Yes, use @PathVariable("name").

30
New cards

Can you change the order of parameters in the URL and in the method?

Yes — match by name, not order.

31
New cards

How do you make a path parameter optional?

@PathVariable(name = "param", required = false).

32
New cards

Why is it risky to leave out path parameters in the middle of a URL?

It can cause ambiguity — the server may misinterpret which value goes with which parameter.

33
New cards

What's the fix for ambiguous paths?

Use labelled segments like /fruit/lemon/colour/yellow.

34
New cards

How do you access all path parameters in a map?

@PathVariable Map<String, String> pathParams.

35
New cards

How does a client include path parameters?

By inserting them directly into the URI path:

java

new URI("http://.../simple-path/5/6")

36
New cards

How do you read a header in Spring Boot?

Using @RequestHeader("headerName").

37
New cards

How do you make a header optional?

Add required = false or defaultValue.

38
New cards

How do you read all headers into a map?

Use @RequestHeader Map<String, String>.

39
New cards

What is the HttpHeaders class used for?

It gives access to standard headers like content type, and you can still use .get("customHeader").

40
New cards

How do you access all values of a multi-valued header?

Use @RequestHeader MultiValueMap<String, String>.

41
New cards

How does a client set headers in Java?

Use .header("Header-Name", "value") when building the request.

42
New cards

How do you read body content in Spring Boot?

use @RequestBody.

43
New cards

Can you have more than one @RequestBody parameter?

No — only one per method.

44
New cards

How do you make a body parameter optional?

@RequestBody(required = false)

45
New cards

What's the most common use for @RequestBody?

Sending structured data like JSON, mapped to a Java object.

46
New cards

What happens if no @RequestBody is present and it's required?

Spring will throw a 400 (Bad Request) error.

47
New cards

How does Spring convert JSON into a Java object?

Using the Jackson library (automatically if types match).

48
New cards

Why are there multiple parameter passing mechanisms in REST?

Because not all mechanisms are equally capable, HTTP doesn't support all combinations, and there are best practices for choosing the right one based on context

49
New cards

What type of parameter is best for hierarchical navigation in REST?

Path Parameters

50
New cards

What is the recommended way to filter data in REST?

Use query parameters for filtering.

51
New cards

How many body parameters can a REST method have?

1

52
New cards

Which parameter type is best suited for structured data like JSON?

Body Parameters

53
New cards

What does the 'produces' attribute specify in a REST method?

The content type of the data returned in the response body.

54
New cards

What does the 'consumes' attribute specify in a REST method?

The content type of the data accepted in the request body.

55
New cards

Can a method consume multiple content

Yes, by listing them in the 'consumes' attribute.

56
New cards

What is the purpose of a maturity model?

To assess how well processes are defined, managed, and optimized in software development

57
New cards

What are the five levels of the CMM model?

Initial, Repeatable, Defined, Managed, Optimizing.

58
New cards

What are the four levels of the Richardson Maturity Model?

Level 0: Single Endpoint, Level 1: Multiple URIs, Level 2: Use of HTTP verbs, Level 3: Hypermedia Controls (HATEOAS).

59
New cards

What is the risk of skipping REST maturity levels?

Clients become tightly coupled to URI structure, making it hard to evolve the API.

60
New cards

What HTTP method can be used to support HATEOAS?

OPTIONS, although Spring Boot usually uses enhanced GET responses for this.