geekIndiana
geekIndiana

Reputation: 87

Restlet basic HTTP Authentication : Help required

I am running Restful web service on 8182 port using restlet framework. I am trying to authenticate user to hit the service. i.g.

I have a query string like this http://localhost:8182/api/service/customers/?key="XXXXXXXXX"

My doubts are:

  1. How to get value of parameter key in Resource class/Application class, so i can authenticate user upon key through my custom database.

  2. I don't have any client code for my restful service, since i want to invoke all call from browser itself. so please tell me,how to send post data from browser itself. since i want to use post/put method to add new customer data.

I am using restlet framework 1.1.

Thanks in advance.

Karunjay Anand

Upvotes: 1

Views: 1130

Answers (2)

Jordan Allan
Jordan Allan

Reputation: 4486

As Bruno pointed out, you can obtain a Form instance to access the request's query parameters:

Form form = getRequest().getResourceRef().getQueryAsForm();
for (Parameter p : form) {
    System.out.println("Name: " + p.getName());
    System.out.println("Value: " + p.getValue());
}

If you want to use the POST method from the browser itself, I would recommend you use one of the following add-on/extensions:

Firefox - REST Client

Google Chrome - Simple REST Client

Upvotes: 0

Bruno
Bruno

Reputation: 122769

You can use:

getRequest().getResourceRef().getQueryAsForm()

This will return a Form instance from which you can get the value of your query parameters (getFirstValue("key"), for example).

Upvotes: 1

Related Questions