Define multiple request parameters in a REST web service

Does anyone know how to set multiple request parameters in a REST web service? I am writing using java.My curl sample looks like this:

curl -X PUT http://localhost:8080/project/resources/user/directory/sub-directory?name=shareuser&type=Read -v 

My program:

 @PUT @Path("{user}/{directory:.+}") public Response doshare(@PathParam("user")String name, @PathParam("directory")String dir, @QueryParam("name")String sharename, @QueryParam("type")String type){ mongoDAOImpl impl=new mongoDAOImpl(); Mongo mongo=impl.getConnection("127.0.0.1","27017"); DB db=impl.getDataBase(mongo,"public"); DBCollection coll=impl.getColl(db,name); DBCollection coll2=impl.getColl(db,"sharedb"); shareDTO sharedto=new shareDTO(); String authority=type.toLowerCase(); if(authority.equals("rd")){ sharedto.setAuthority("4"); }else if(authority.equals("rw")){ sharedto.setAuthority("12"); } sharedto.setTargetuser(sharename); sharedto.setRealURI("/home/public/"+name+"/"+dir); sharedto.setIdentifier(name); sharedto.setParentURI("/home/public/"+sharename); boolean bool = false; sharefun=new sharefunction(); if(sharefun.checksubfoldershared(coll, coll2, sharedto)){ bool=sharefun.sharefiles(coll, coll2, sharedto); }else{ System.out.println("Error"); } // ... 

But I only get the name query parameter. How to get or how to enter curl command to get all query parameters?

+4
source share
3 answers

Your code is fine - the problem is how you call curl. When passing the URL for a curl containing &, you must include quotation marks around the URL. Otherwise, the shell will interpret the material after "&". as a separate team.

EDIT: my text is hushed up when I post it as a comment. Here is what you need to do:

 curl -X PUT 'http://localhost:8080/project/resources/user/directory/sub-directory?name=shareuser&type=Read' -v 
+19
source

You can try to treat all this as a multi-page download (server-side details are not standardized, and you did not say which infrastructure you are using, so I can not give more hints), but I doubt re that has the user and permissions set ( using any parameters) first. Surely you would be better off storing the user by checking the user credentials and using the default permission set, which they can change later? Almost as cheap and much easier.

+1
source

Have you tried using the -d option? eg.

 curl -X PUT -d "name=shareuser&type=Read" http://locahost:8080/project/resources/user/directory/sub-directory -v 
0
source

All Articles