Welcome to 16892 Developer Community-Open, Learning,Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am writing my web server and suddenly this question came into my mind.

There are two ways to pass parameters via a GET method. First is to user get parameters, such as url/?para=var or so. But I can also hard write this parameter in URL as long as my backend parser knows it, like url/<parameter>/. What's the difference between those methods and which is better?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
1.1k views
Welcome To Ask or Share your Answers For Others

1 Answer

Path parameters

Use path parameters when the parameter identifies a specific entity.

For example, consider a blog. The URL /blog/posts returns a collection with all posts available in the blog. To find the blog post with the identifier sending-parameters-in-http, use the following:

GET /blog/posts/sending-parameters-in-http

If no blog post is found with the identifier sending-parameters-in-http, a 404 status code should be returned.

Query parameters

Use query parameters to filter a collection of resources.

For example, consider you need to filter the blog posts with the java tag:

GET /blog/posts?tag=java

If no posts are found with the java tag, a 200 status code with an empty array should be returned.

Query parameters can be used for paging:

GET /blog/posts?start=1&limit=10

The also can be used when sorting resources of a collection:

GET /blog/posts?sort=title

To get a set of posts with the java tag sorted by title, you would have something as following:

GET /blog/posts?start=1&limit=10&tag=java&sort=title

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to 16892 Developer Community-Open, Learning and Share
...