Proper usage of POST request to MUSCLE in angularjs
0
1
Entering edit mode
8.2 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!

angularjs muscle rest post • 3.5k views
ADD COMMENT
0
Entering edit mode

What does the error callback portion of the promise report to the console?

ADD REPLY
0
Entering edit mode
Object { data: null, status: -1, headers: fd/<(), config: Object, statusText: "" }
Object { method: "POST", transformRequest: Array[1], transformResponse: Array[1], paramSerializer: nf/this.$get/<(), url: "http://www.ebi.ac.uk/Tools/services…", data: Object, headers: Object }
ADD REPLY
1
Entering edit mode

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.

ADD REPLY
0
Entering edit mode

I just checked by doing a request with a very small data sample and the error continued.

ADD REPLY
1
Entering edit mode

I would suggest debugging the REST request with a non-AngularJS based approach.

For example, using wget:

$ wget -O- \
    --post-data='{ \
              "email" : "...", \
              "title" : "...", \
              "format" : "...", \
              "tree" : "...", \
              "order" : "...", \
              "sequence" : "..."}' \
    --header="Content-Type:application/json" \
    "http://www.ebi.ac.uk/Tools/services/rest/muscle/run"

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 like wget or curl.

If you are using wget or curl 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.

ADD REPLY

Login before adding your answer.

Traffic: 3135 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6