Such as by id can I obtain a user's information, I can design the API
GET [host] : [port]/API/v1/users/{id}
The background, I can use a @ PathVariable receive
I want to get all users,
I can design the API
GET [host] : [port]/API/v1/users
So in the meantime, I have another demand, I want to by name for user information, how do I design the API?
If I so design API
GET [host] : [port]/API/v1/users/{name}
Or
GET [host] : [port]/API/v1/users? Name={name}
This is not possible, because Spring is not allowed to repeat the url,
GET [host] : [port]/API/v1/users/{id}
And
GET [host] : [port]/API/v1/users/{name}
Url is the same, it is not allowed.
GET [host] : [port]/API/v1/users? Name={name}
And
GET [host] : [port]/API/v1/users
The same
So the question comes, what should I design for a particular field is equal to a value of API?
Or, I give up the Controller of automatic assignment function, receives a url all parameters, access to the content, and then judge calls the corresponding business?
This is I see a big design API, so like this & gt;=, & lt;=,=-=+, the background how to obtain, string to judge, if I could only use the Controller gain=the value of the
CodePudding user response:
Can't change the name, this don't tangle [host] : [port]/API/v1/username/{name} indicate the need to find the key parameters, the third fourth specify parameter valuesCodePudding user response:
So whether id and the name can be incorporated into a [host] : [port]/API/v1/{searchkey}/{searchvalue}CodePudding user response:
Why the parameter value in the URL, directly passed as a parameter not quick zaiTwo interfaces
GET [host] : [port]/API/v1/users/id
Corresponding getById (id)
GET [host] : [port]/API/v1/users/name
Corresponding getByName (String name)
CodePudding user response: