java - Web Api parameter design style -


i try design simple web api using spring. there 1 parameter array of string, api looks

   public string test(string[] pars){} 

or there way, take 1 string parameter , split using separator ";" or ":",the api this:

     public string test(string par){          string pars = par.split(":");        } 

i want know pros , cons of each other

your first option best many reasons.

the important 1 default way html/http send multiple values same parameter, send parameter multiple times. used checkboxes , multi-select options lists in html forms.

another reason supported out of box spring webmvc:

@controller @requestmapping("/test") public class testcontroller {      @requestmapping(method = requestmethod.get)       public string test(@requestparam("pars") string[] pars){} } 

to pass array use url

http://yourhost/test?pars=par1&pars=par2&pars=par3 

obviously disadvantages of second method suggested not standard way in html/http communicates multi-value parameters, , not supported spring webmvc out of box.

the advantage of second method url bit shorter, issue when doing requests, not post requests. if keep parameter name short, not major issue.


Comments

Popular posts from this blog

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -