Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mixing Resources (REST) and Non-Resources

Tags:

java

rest

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).

like image 453
Jason Avatar asked Nov 22 '25 01:11

Jason


1 Answers

Yes it is ok to have your random number generator method decorated like

@GET
@Path("util/randomNumber")
public Response getRandom(...)
like image 171
Jay Parashar Avatar answered Nov 24 '25 15:11

Jay Parashar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!