Path Param & Body Param & Query Param

Ladynobug
2 min readMay 27, 2022

--

What are they? When to use?

1. path param — Identify a specific resource or resources

in another example, /vmware/vm/virtualMachine:::1234 here /vmware/vm/{id} id is the path param.

Query parameters are added at the end of the URL, and thus can allow omission of some values as long as the serializing standards are followed.

2. query param — Change the scope of the request

e.g. sort, filter/match a name, type, size, state, etc.

for example — https://example.com/articles?sort=ASC&page=2

sort=ASC is a query param.

They can be used in filtering criteria, sorting criteria, or to represent the current page number in a paginated collection.

(Speaking of pagination, look at here — https://medium.com/@LadyNoBug/api-pagination-24b36b77d577)

/vmware/vm?is_relic=true or

/vmware/vm?is_relic=true&sort_by=effectiveSlaDomainName

3. body param (payload) — to upload or download

in another example, https://wahlnetwork.com/2017/09/25/working-with-restful-api-query-body-and-path-parameters/#Path_Parameter you can find the BODY PARAM in the form of JSON payload, where both path and body params are passed in the same endpoint.

Usually, the content body is used for the data that is to be uploaded/downloaded to/from the server, and the query parameters are used to specify the exact data requested.

so…

Path / query / body params

  1. For example, when you upload a file you specify the name, mime type, etc. in the body but when you fetch the list of files you can use the query parameters to filter the list by some property of the files. In general, the query parameters are properties of the query, not the data.
  2. POST should not have query param. You can implement the service to honor the query param, but this is against REST spec. “Why do you pass it in a query param?” Because, like for GET requests, the query parameters are used to refer to an existing resource.
  3. Does POST request need a body? Yes, it is expected to have Body/Content in the body, but it is not required(Mandatory). (TODO: example of this)

--

--

Ladynobug

A growing software engineer. An aspiring entrepreneur. A curious life learner