joemfb / ml-common-ng

An angular module of common components for the MarkLogic REST API
https://joemfb.github.io/ml-common-ng/
2 stars 2 forks source link

Support additional config headers in MLRest/request function #25

Open guyduplantier opened 8 years ago

guyduplantier commented 8 years ago

All configuration headers are not passed to the $http service from the request(endpoint,settings) function, ml-common-ng.js:172. For example when calling an ML extension that returns a PDF, I need to set the responseType to "arraybuffer". Current code doesn't support this.

grtjn commented 8 years ago

You are referring to this line: https://github.com/joemfb/ml-common-ng/blob/master/dist/ml-common-ng.js#L172, right?

I could be mistaken, but if I read correctly, settings.headers is passed through untouched.

grtjn commented 8 years ago

I recall other places where headers weren't always passed through to mlrest.request, though can't name them from the top of my head..

guyduplantier commented 8 years ago

Hi Geert,

The line you reference is correct.

This is not an HTTP header, it's a configuration item, responseType. See https://docs.angularjs.org/api/ng/service/$http#usage.

I tested the below update and it worked for me. Any idea why all settings aren't passed through?

return $http({ url: url, data: settings.data, method: settings.method, params: settings.params, headers: settings.headers, responseType: settings.responseType });

On Thu, Sep 15, 2016 at 2:22 PM, Geert notifications@github.com wrote:

I recall other places where headers weren't always passed through to mlrest.request, though can't name them from the top of my head..

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/joemfb/ml-common-ng/issues/25#issuecomment-247409359, or mute the thread https://github.com/notifications/unsubscribe-auth/ADflZRG1ovG_HzOaHDyDE90pHXoMCAe6ks5qqYzlgaJpZM4J94z3 .

grtjn commented 8 years ago

Interesting. I must have misunderstood your meaning for 'headers'. That aside, i don't recall having heard of any of us to have tried streaming binaries through mlrest. We usually embed a pdf viewer, and make that connect to /v1/docs directly..

guyduplantier commented 8 years ago

Geert,

These PDFs are generated on the fly. ML stands between a Webapp and an XML/FO instance that creates then. ML returns the PDF to the client. We could change our architecture to bypass ML, but it's easier to manipulate the XML there.

This aside, shouldn't ml-commons-ng support all the configuration options that the Angular $http service does?

Thanks,

Guy

On Thu, Sep 15, 2016 at 5:01 PM, Geert notifications@github.com wrote:

Interesting. I must have misunderstood your meaning for 'headers'. That aside, i don't recall having heard of any of us to have tried streaming binaries through mlrest. We usually embed a pdf viewer, and make that connect to /v1/docs directly..

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/joemfb/ml-common-ng/issues/25#issuecomment-247454505, or mute the thread https://github.com/notifications/unsubscribe-auth/ADflZbIi3AwC1xmNyaUfm2fcVeBl4t7rks5qqbJGgaJpZM4J94z3 .

grtjn commented 8 years ago

You could bypass ML, but that is not what i meant. I meant bypassing Angular.

I would just make Angular insert a download button in your frontend html that points to your ML rest extension. I dont think it will be usefull to try to capture the binary stream inside the browser side javascript code, with the only purpose of passing it through to the end user for download or viewing.

Talking about that, are you aware of my latest grtjn/view-file-ng directive? You might find it usefull..

Returning to your actual question: yes it would sometimes be convenient to have access to all options of underlying methods. But that isnt always practical. Personally, i think it only makes sense if it otherwise prevents you making full use of ml rest api. You're the first to ask for that config option..

guyduplantier commented 8 years ago

Hi Geert, I'll investigate the download button and take a look at the view-file-ng directive. Thanks,

Guy

On Fri, Sep 16, 2016 at 4:47 PM, Geert notifications@github.com wrote:

You could bypass ML, but that is not what i meant. I meant bypassing Angular.

I would just make Angular insert a download button in your frontend html that points to your ML rest extension. I dont think it will be usefull to try to capture the binary stream inside the browser side javascript code, with the only purpose of passing it through to the end user for download or viewing.

Talking about that, are you aware of my latest grtjn/view-file-ng directive? You might find it usefull..

Returning to your actual question: yes it would sometimes be convenient to have access to all options of underlying methods. But that isnt always practical. Personally, i think it only makes sense if it otherwise prevents you making full use of ml rest api. You're the first to ask for that config option..

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/joemfb/ml-common-ng/issues/25#issuecomment-247705155, or mute the thread https://github.com/notifications/unsubscribe-auth/ADflZTwZPqZNsGD3QuWfNDc-9MStRvSDks5qqwBSgaJpZM4J94z3 .