0

We can use

'PATCH /companies/:id' : 'CompanyController.find'

to update data.

One suggested me that I can use the alternative way:

'PATCH /companies/find?key=Value' 

But I do not know what it works. Please explain me why we prefer ? mark than : mark in search path.

unor
  • 82,883
  • 20
  • 183
  • 315

4 Answers4

0

You can use either or. The biggest reason most people chose one or the other is just how they want to present the URL to the user.

Using a path variable (:) can symbolize you're accessing a defined resource, like a user ID, where as an argument (?) can symbolize you're are dynamically changing/searching something within a defined resource, like a token or search term.

From what I can tell that's the general practice I see:

example.com/user/:username

versus

example.com/user/?search="foo"
unor
  • 82,883
  • 20
  • 183
  • 315
GhostfromTexas
  • 171
  • 1
  • 5
0

http://en.wikipedia.org/wiki/URL

If we are firing GET request, ? symbol is used to let the server know the url parameter variables starts from there. And this is commonly used. I didn't used : symbol instead of ?

vishnu
  • 165
  • 1
  • 14
0

You are probably messing the things up:

  • According to your example, :id indicates a variable that must me replaced by an actual value in some frameworks such as Express. See the documentation for details.

  • And ? indicates the beginning of the query string component according to the RFC 3986.

cassiomolin
  • 101,346
  • 24
  • 214
  • 283
-2

It's a rule to design rest api
you can find 'how to design a rest api'

Assuming below code is Sails.js

'PATCH /companies/:id' : 'CompanyController.find'

It will makes REST API that be mapped onto 'CompanyController.find' by using PathParam. Like this

www.example.com/companies/100

Second one will makes REST API by using QueryParam.
It also be mapped onto 'CompanyController.find'

/companies/find?key=Value

But the API format is different. Like this

www.example.com/companies/find?key=100

PathParam or QueryParam is fine to make REST API.
If the Key is primary for company entity, I think PathParam is more proper than QueryParam.

yoon
  • 30
  • 2