1

I'm trying to write a Java client (with Apache HttpClient) for the Gengo API which makes use of HTTP GET, POST, PUT and DELETE. However for every RESTful API "method" that they expose, you must pass your API key and signature as "parameters".

Would this mean query string parameters, POST variables, key-value pair headers, or something else?

I guess I'm just confused by what is meant by the word "parameters" in the context of all these different HTTP request methods. In other words, how would I pass the API key as a "parameter" to their API when I could be using GET, POST, PUT or DELETE? My understanding was that only HTTP GET can handle query string params, and that HTTP POST can only handle POST variables. And I have never used PUT or DELETE before so I'm not sure what they require.

So I ask: what mechanism can I use to send the API key/signature via all 4 types of request methods, or do they all support the processing of query string parameters? Thanks in advance.

2
  • Maybe this is what you want [HTTP testing tool, easily send POST/GET/PUT]: stackoverflow.com/questions/1087185/… Commented Dec 27, 2012 at 15:35
  • Thanks @MrSmith42 but no, that's not what I'm looking for. What I'm really asking here is how the different request methods (GET, POST, PUT, DELETE, etc.) handle "parameters" differently. For instance, it may be that I have to attach the API key as a query string param for any GET request, and attach the same key as a POST variable for any POST requests, etc. Or it may be that they all can process query string params. Or something else. Commented Dec 27, 2012 at 15:38

2 Answers 2

1

You can try this. It works for my HttpClient application with POST request.

DefaultHttpClient httpClient = new DefaultHttpClient();
httpClient.getParams().setParameter(name, value);
......

For Example, I set the connection timeout:

httpClient.getParams().setIntParameter(HttpConnectionParams.CONNECTION_TIMEOUT, httpTimeout);

Then later, to send(execute) the request:

HttpResponse response = httpClient.execute([My HttpPost instance was here, but I think you can use HttpGet, HttpPut, and HttpDelete here as well]);
Sign up to request clarification or add additional context in comments.

Comments

0

All verbs can use request parameters (also known as query parameters) and they will be available to the server in the same way regardless of if you also send a body.

In your example (Gengo) there is a good example on there page about authentication.

3 Comments

Thanks @Andreas Wederbrand (+1) - however your answer still leaves me confused! It sounds like you're implying that I should be able to append api_key as a query string param (example: http://api.gengo.com/v2/account/stats?api_key=whatever), but in the link that you gave, the PHP example is appending the api_key as a POST variable. This is the root of my question! Which do I use for all 4 methods? Or do they all handle "parameters" differently, and if so, how? Thanks again!
In other words, can I just use http://api.gengo.com/v2/account/stats?api_key=whatever for every single API call (regardless of whether I'm GETting, POSTing, PUTting or DELETEing) or, like the example in your link, do I have to use a different approach for each of those 4 methods?
Right. Parameters are allowed on all verbs but I don't know ff Gengo allows parameters when doing POST and PUT. All you can do is try or ask Gengo support. I would guess that it will work to put it as ?api_key=<key> even on POST and PUT. Don't forget to also add ts= and api_sig=

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.