Our server currently serves a REST-ful API that allows the user to CRUD resources as expected.
What happens if we have something that is not a resource, such as helper data? Do we have to stick to the strict REST-ful convention?
For instance, let's say we have dog in a REST-ful API:
GET: /dogs/
GET: /dogs/:id
POST: /dogs/
PUT: /dogs/:id
DELETE: /dogs/:id
is it okay to add something like:
GET: /util/randomNumber/
that returns a random number?
It's not really a resource since you wouldn't ever update it, or delete it, and cannot be part of a collection. It's not dependable either since it will change on every hit.
(note, I'm not actually trying to generate random numbers. Just an example).
Yes it is ok to have your random number generator method decorated like
@GET
@Path("util/randomNumber")
public Response getRandom(...)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With