Skip to content Skip to sidebar Skip to footer

Url Path Parameters Vs Query Parameters In Django

I've looked around for a little while now and can't seem to find anything that even touches on the differences. As the title states, I'm trying to find out what difference getting

Solution 1:

This would depend on what architectural pattern you would like to adhere to. For example, according to the REST architectural pattern (which we can argue is the most common), you want do design URLs such that without query params, they point to "resources" which roughly correspond to nouns in your application and then HTTP verbs correspond to actions you can perform on that resource.

If, for instance, your application has users, you would want to design URLs like this:

GET /users/ # gets all users
POST /users/ # creates a new user
GET /users/<id>/ # gets a user with that id. Notice this url still points to a user resource
PUT /users/<id> # updates an existing user's information
DELETE /users/<id> # deletes a user

You could then use query params to filter a set of users at a resource. For example, to get users that are active, your URL would look something like

/users?active=true

So to summarize, query params vs. path params depends on your architectural preference.

A more detailed explanation of REST: http://www.vinaysahni.com/best-practices-for-a-pragmatic-restful-api

Roy Fielding's version if you want to get really academic: http://www.ics.uci.edu/~fielding/pubs/dissertation/rest_arch_style.htm

Post a Comment for "Url Path Parameters Vs Query Parameters In Django"