Some questions about RESTful style interface

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?

Jun.21,2021

you don't have to write this in / zoos/ID/animals/ID .
can't have verbs. It doesn't mean you won't be allowed to use parameters.
you can also use some parameters for Filter

.
 

I will design it this way

list all animals: / zoos/animals
list giant panda zoos: / zoos?animal=panda
list all animals in Ocean Zoo: / zoos/animals?zootype=sea

list zoos without giant pandas: / zoospecific zoos panda
list zoos with giant pandas and tigers: / zoos?animal=panda,tiger
list zoos with giant pandas or tigers: / zoos?animal=panda | tiger
list zoos without giant pandas but with tigers: / zoospecific animals pandatiger

Menu