refer to the restful style when writing the interface, Ruan Yifeng RESTful API Design Guide
there are the following examples
GET /zoos:
POST /zoos:
GET /zoos/ID:
PUT /zoos/ID:
PATCH /zoos/ID:
DELETE /zoos/ID:
GET /zoos/ID/animals:
DELETE /zoos/ID/animals/ID:
but in practical application, it is not that simple, for example, there is an interface:
list all animals: path
is / zoos/all/animals/all
or / animals
,
according to the purpose of the interface, I only care about animals / animals
seems to be more appropriate, but it coincides with the / zoos/ID/animals
function, and two routes need to be maintained in the background
list the giant panda zoos: path
,
list all the animals in the Ocean Zoo: path
,
there are usually many filter conditions in the actual interface, and the scope will not be narrowed down level by level like country > province > municipality > district > road
.
in this case, it seems very simple to write the interface in the traditional way.
getZoos?city= Guangzhou & anamal_type= Giant Panda
getZoos?zoo_type= Aquarium
getAnimals?anamal_type= Marine Life
at the beginning of the interface, the function is simple, and it is very elegant to use restful, but the function becomes complex, so it seems that it is not very suitable, and the version of the interface has not reached the level of upgrade, so there will be two ways to write it side by side, so embarrassing!
how do you do it!
are there any examples of restful with more complex functions?