Entering edit mode
6.5 years ago
derek.jow
▴
10
I am wondering what the proper syntax is (in angular) for issuing a POST request to MUSCLE web services (The Run request). I tried submitting my data in both json and urlencoded, but I only received an error status callback of -1.
Here is a snippet of the code I am using
// data to send to muscle
var content = {
email: "...",
title: "...",
format: "...",
tree: "...",
order: "...",
sequence: data.join()
};
Longhand with url encoded:
$http({
method: 'POST',
url: 'http://www.ebi.ac.uk/Tools/services/rest/muscle/run/',
data: content,
headers: {
'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8'
},
transformRequest: [function(data) {
return angular.isObject(data) && String(data) !== '[object File]' ? $httpParamSerializer(data) : data;
}]
}).then (function successCallback(response) {
console.log("SUCCESS");
}, function errorCallback(response) {
console.log("ERROR");
console.log(response);
console.log(response.headers);
console.log(response.config);
});
Shorthand with json (as default config):
// submit post to MUSCLE
$http.post('http://www.ebi.ac.uk/Tools/services/rest/muscle/run/', content).then(function (success) { ....
Any help would be very much appreciated. Thanks!
What does the error callback portion of the promise report to the console?
I searched on
angularjs http status "-1"
and saw mention of a timeout error. Reading the "Important" section of the REST docs at: http://www.ebi.ac.uk/Tools/webservices/services/msa/muscle_rest I saw that they have limits on the amount of data and number of requests allowed over time. Are you perhaps going over that and they are temporarily blocking access? That might cause your requests to timeout.I just checked by doing a request with a very small data sample and the error continued.
I would suggest debugging the REST request with a non-AngularJS based approach.
For example, using
wget
:Or similar.
Basically, the idea is to validate that your JSON payload is correct, that your header is correct (what I have is different from your AngularJS call — you might check that your payload MIME type,
application/json
, matches the header you are setting), and that the EBI service will respond to that data and header with a valid 200 response and some kind of answer, using a basic command-line tool likewget
orcurl
.If you are using
wget
orcurl
and getting 408 or other timeout related http errors, then you might be running into the issue I mentioned earlier, where EBI is temporarily blocking access from your host, perhaps if you are sending too many requests, too many large requests, or too frequent requests. In that case, I think the only solutions are to wait or to contact their support for feedback.Once you have validated that the payload and header you are sending to their service are correct, then you can start investigating and debugging the other parts of the AngularJS
$http()
call.