Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

URL Path Parameter Use Cases

Normally when I think of parameters in an URL, I think of the query string. Technically, however, it is also legal to specify parameters in the path segments. Thus given a URL like this:

http://www.a.com/frisbee/brand

It is legal to write this instead:

http://www.a.com/frisbee;color=red;size=small/brand;test=1

In practice I never see this. What frameworks, if any, do make use of this?

I'm working with ASP.NET MVC3 of late, and I'm not sure it can extract these kinds of parameters.

like image 553
Brent Arias Avatar asked Jul 20 '11 17:07

Brent Arias


People also ask

What are URL parameters used for?

What Are URL Parameters? URL parameters (known also as “query strings” or “URL query parameters”) are elements inserted in your URLs to help you filter and organize content or track information on your website. To identify a URL parameter, refer to the portion of the URL that comes after a question mark (?).

What is URL path parameter?

Path parameters are variable parts of a URL path. They are typically used to point to a specific resource within a collection, such as a user identified by ID. A URL can have several path parameters, each denoted with curly braces { } .

What is path parameter example?

Path Parameter Example Path parameters are part of the endpoint and are required. For example, `/users/{id}`, `{id}` is the path parameter of the endpoint `/users`- it is pointing to a specific user's record. An endpoint can have multiple path parameters, like in the example `/organizations/{orgId}/members/{memberId}`.

Should you use URL parameters?

Website URL parameters are commonly used for tracking session IDs, product category page filters, powering search queries and more. Parameters can be valuable but do confuse search engines, resulting in page indexing issues and wasted crawl budget.


2 Answers

Many modern framework will support specifying variables as part of a path segment, in their URL-parsing systems.

Symfony (PHP) and Django (Python) would both support this as they support extracting values from URLs via regular expressions.

One significant difference is that parameters specified in the query string can usually be in any order, because they will typically be parsed into a dictionary-like structure. That wouldn't apply to parameters in a path segment. You could of course parse them yourself into a dictionary, but the frameworks I just mentioned won't help you do that.

Note that technically the order of the parameters is significant in an HTTP URI anyway, i.e. a conforming comparison of two URLs where the parameters (in the path or in the query string) were in a different order would have to assume that they could reference a different resource.

like image 61
George Lund Avatar answered Oct 15 '22 19:10

George Lund


Java Servlet Containers uses URL rewriting to maintain session state when the client does not support cookies by appending a path parameter. The servlet specification says the path parameter must be named jsessionid

e.g. http://example.com/servlet_path;jessionid=E60FF3ABD2926AD9AA45513A385E373D

To get this working you must be careful to always pass the URLs you send back to the client through response.encodeURL() or response.encodeRedirectURL() so that the container can add the necessary path parameter.

Further support is demanded by the specification for mapping requests to servlets

The path used for mapping to a servlet is the request URL from the request object minus the context path and the path parameters

like image 20
scarba05 Avatar answered Oct 15 '22 19:10

scarba05