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
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…