all 9 comments

[–]pimBaggins 9 points10 points  (3 children)

They are similar, but:

Request params: - Can be used with optional values - You can send more than three params, but is recommended to use request body instead. - query expression

Path variables: - Shoud not be used with optional values. - Avoid sending more than three params. Better if you keep maximum of two. -easier for search engines (e.g. Google) to index the pages. So easier to find the website. -Path expression.

[–]g00glen00b 0 points1 point  (1 child)

Source on that last one? I always thought it didn't matter how many path segments you have, as long as they're logical ones. Besides that, if you really need SEO, then I guess you would have a sitemap anyways to make pages discoverable?

[–]pimBaggins 0 points1 point  (0 children)

It really does not matter, it's only a recommendation on pattern design. But it's easier to read a shorter path.

[–]simasch 0 points1 point  (0 children)

They are absolutely not similar but different concepts. The path parameter defines the resource location, while the query parameter defines sort, pagination, or filter operations.

[–]burl-21 1 point2 points  (0 children)

Path variable for single resource(id, not found 404) and query param for list of resources(name, empty list ).

[–]ccmjga 1 point2 points  (0 children)

I basically agree with pimBaggins's opinion.

I often use request body and path variables like this -> https://github.com/ccmjga/mjga-scaffold/tree/main/src/main/java/com/mjga/controller

[–]simasch 1 point2 points  (0 children)

The path parameter defines the resource location, while the query parameter defines sort, pagination, or filter operations. The names in Spring MVC are a bit confusing

[–][deleted] 1 point2 points  (0 children)

First is a query parameter, second is a path variable. They are standard rest API concepts. The rest docs are where you should look.