jax rs - REST API getById using Integer or String? -
i'm designing rest jax-rs api jersey.
i want know best practice object id. need map id on integer or string
solution 1:
/books/{id} getbyid(@pathparam("id") long id) solution 2:
/books/{id} getbyid(@pathparam("id") string id) my intention used long because directly mapped on database model using long...
if need long, make parameter long.
if jax-rs can't map path parameter requested client long, return 404 not found http status code thing. if allow string, code have check. let jax-rs checking.
@get @path("/books/{id}") public response getbook(@pathparam("id") long id) { return response.ok("book " + id).build(); } a request /books/123 return book 123. request /books/foo fail 404 not found.
Comments
Post a Comment