java - RESTful thru JAX-RS, what is the common usage for @QueryParam and @Consume? -
i new comer in terms of web services. tasked convert existing software component web service. did research , decided use jax-rs. having difficulty decide when use @queryparam , when use @consume because seems able achieve same goal.
for example, let have method named read() , takes book argument.
public class areader { public void read(book book){...} } public class book { public string author; public string name; }
when translating using jax-rs annotation, either
- use @post , @queryparam accept author , name parameter or
- use @post , @consumes consume text representation of book in xml or json format in body.
my question common usage @queryparam , @consume. personal preference or there common practice?
i found lot information usage of @pathparam , @queryparam not @queryparam , @consumes.
thanks in advance...
query parameters ideally best suited representing aspects of requests have nothing resource representation.
for example, if designing restful web service, , if you're creating new book via post request, body of request should ideally contain resource representation in desired media type - application/json
, text/xml
, application/x-www-form-urlencoded
etc. providing resource representation via query parameters not on lines of how http-based rest apis designed. additionally, query parameters can omitted , provided resource representation incomplete, against design principles require complete resource representations provided in post , put operations.
query paremeters more suitable requests. want paginated collection of requests, accept requests /books?start=0&pagesize=10
obtain first 10 books.
Comments
Post a Comment