Param Vs Slug
2 min read
Table of contents
In web development, both "param" and "slug" are terms that refer to specific types of values in a URL, but they have different roles. Here's a breakdown of each:
Param (Parameter)
Definition: A "param" (short for parameter) typically refers to a key-value pair in a URL that provides additional data to the server. Params are usually part of the query string in the URL.
Format: Params appear after a question mark
?
in the URL, with key-value pairs separated by an equals sign=
and each pair separated by an ampersand&
.Example:
https://example.com/products?category=electronics&id=1234
Here,
category=electronics
andid=1234
are params. They provide data (category and ID) that the server can use to filter or process the request.Use Case: Params are used for things like filtering data (e.g.,
category=electronics
) or passing information to a server for processing (e.g.,id=1234
).
Slug
Definition: A "slug" is a part of the URL that typically represents a human-readable, SEO-friendly identifier for a resource (e.g., a blog post, product, or page). It is often derived from a title or name.
Format: A slug usually appears as a part of the URL path, often replacing spaces with hyphens (
-
) and making all characters lowercase for readability and SEO purposes.Example:
https://example.com/blog/how-to-learn-python
Here,
how-to-learn-python
is the slug. It is a descriptive, readable identifier for the blog post.Use Case: Slugs are used to make URLs more understandable for users and search engines, often reflecting the name or title of a resource.
Key Differences
Location in URL:
Params are typically found in the query string (after the
?
symbol).Slugs are found in the URL path (after the domain name, often in the form of readable text).
Purpose:
Params provide extra data for processing the request (like filtering or identifying specific resources).
Slugs represent readable identifiers for resources (like pages, blog posts, or products).
Example Comparing Both:
https://example.com/products/electronics?sort=price&filter=on-sale
Slug:
electronics
is a slug, representing a category of products.Params:
sort=price
andfilter=on-sale
are parameters, specifying how the products should be filtered and sorted.
In summary, slugs are used for human-readable, SEO-friendly URLs that describe the resource, while params are typically used to pass dynamic data or configuration settings to the server.