I am creating a web service and I follow the RESTful way of doing it. So I have resources such as Person, Ticket etc. I have all the normal CRUD operations, some finders and so on. I also want to expose service methods such as randomTicket()
which is defined in a RandomTicketGenerator
class. I am unsure if it is bad to expose service methods in a REST API like this? For instance the path above would be /randomTicket
and only answer on GET requests.
/ticket/random
is a bit confusing as it could be interpreted as meaning 'give me the ticket with ID=random'
How about returning a single item via: GET /ticket?random=true
Or a list of items via: GET /tickets?random=true&maxItems=1
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.