Reputation: 13637
I'm defining a RESTful WebService in Java.
It takes as input:
jdoe
);https://blablablabla.io/sample?boh=mah
).By using GET method of the HTTP protocol, it should produce a JSON
file.
Which is the best way to pass these params?
In this particular case, is there a best practice to follow in order to properly pass an URL as param?
Upvotes: 2
Views: 2733
Reputation: 47
Also you can use Path parameters
This is example
@Path("/users")
public class UserResorce {
@GET
@Path("/{username}")
@Produces(MediaType.APPLICATION_JSON)
public String getUser(@PathParam("username") String username)){
}
}
The url is http://domain_name/your_application_path/users/username
Upvotes: -1
Reputation: 8580
If you want to define an http GET
method, then the only way to pass parameters to it is through the URI query string (ie. ?x=y&...
).
This is because GET
calls can not take in a message body.
If you want to pass in more complicated information, you will need to use POST
, PUT
, or some other method. Though, if you are actually just getting information (semantically), then you shouldn't use anything but GET
.
Upvotes: 1
Reputation: 23301
You must first encode it, you can use
URLEncoder.encode("url");
Upvotes: 3