vdenotaris
vdenotaris

Reputation: 13637

Pass an URL as param in RESTful WebServices

I'm defining a RESTful WebService in Java.

It takes as input:

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

Answers (3)

user4132613
user4132613

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

Luke Willis
Luke Willis

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

Rocky Pulley
Rocky Pulley

Reputation: 23301

You must first encode it, you can use

URLEncoder.encode("url");

Upvotes: 3

Related Questions