I am working on writing a blog and came across two different alternatives on the internet for making pagination. I couldn't decide which to use. Url types are like ;
blog/page/2
blog/?page=2
Does one of these have an advantage over the other?
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 { } .
Yes, that's what you should be doing. encodeURIComponent is the correct way to encode a text value for putting in part of a query string. but when it is decoded at the server, the parameters of url are interpreted as seperate parameters and not as part of the single url parameter.
The path parameter defines the resource location, while the query parameter defines sort, pagination, or filter operations. The user's input (the query) is passed as a variable in the query parameter, while each path parameter must be substituted with an actual value when the client makes an API call.
Best practices are that path parameters are used to identify a specific resource, and query parameters filter or sort that resource.
If you are adding a pagination with articles, it would be ideal to use query parameters to sort through the articles. It is common for this query parameter to be referred to as offset
, as you would be filtering through your articles.
So for example if you had 100 articles you've posted, and you want to display 10 articles per pagination page, and you were on page 2 of 10 in your pagination, your offset query parameter would be ?offset=10 because you would be filtering for articles 10-19 to display. (because articles 0-9 were displayed on your first pagination page)
This offset query parameter would increase by 10 every pagination page you increase, then filtering to the next 10 articles.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With