jonsamwell / angular-http-batcher

Enables HTTP batch request with AngularJS
MIT License
96 stars 28 forks source link

Added OData parsing and relative URLs. #2

Closed georgeolson closed 10 years ago

georgeolson commented 10 years ago

It's not clean, but it allows relative service URLs and parses OData responses.

jonsamwell commented 10 years ago

Thanks for this! Could you provide a couple of tests for this behavior?

georgeolson commented 10 years ago

Sure! I’m super busy this week, but I will work on it.

From: Jon Samwell [mailto:notifications@github.com] Sent: Wednesday, October 15, 2014 12:56 PM To: jonsamwell/angular-http-batcher Cc: George Olson Subject: Re: [angular-http-batcher] Added OData parsing and relative URLs. (#2)

Thanks for this! Could you provide a couple of tests for this behavior?

— Reply to this email directly or view it on GitHubhttps://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_jonsamwell_angular-2Dhttp-2Dbatcher_pull_2-23issuecomment-2D59265783&d=AAMCaQ&c=fa_WZs7nNMvOIDyLmzi2sMVHyyC4hN9WQl29lWJQ5Y4&r=B3KJahVz1wyngYqA_Zpz24pE8gP9Q9oX1IO-sTL_HGo&m=omei0OvFqGDyvTWdScycP4qrwuKjlEMBcFhq8GPEYt0&s=YFBkeR_Mx2fWE5srfxSoZZiEJspVTX_g06T6dghxl6Y&e=.

jonsamwell commented 10 years ago

Awesome!

jonsamwell commented 10 years ago

Is there anything I can read to understand what odata needs for batch requests?

georgeolson commented 10 years ago

Spending more time thinking about it I think that it’s not necessarily OData specific. The default formatter for Web API OData indents JSON. This means that the lines can’t be read one by one. Instead the content is taken from everything between the { and } and the headers are everything before.

var content = this.part.substring(this.part.indexOf('{'));

content = content.substring(0, content.lastIndexOf('}') + 1);

result.data = JSON.parse(content);

var headers = this.part.substring(0, this.part.indexOf('{') - 1).split(constants.newline);

For example:

HTTP/1.1 200 OK Cache-Control: no-cache Pragma: no-cache Content-Type: application/json; charset=utf-8 Expires: -1 Server: Microsoft-IIS/8.0 X-AspNet-Version: 4.0.30319 X-SourceFiles: =?UTF-8?B?QzpcVXNlcnNcZ2Vvcmdlb1xTb3VyY2VcV29ya3NwYWNlc1xGb3JlbnNpY3NcRGJoZGQuRm9yZW5zaWNzXERiaGRkLkZvcmVuc2ljcy5XZWJIb3N0XGFwaVxGaWxlc1xFdmFsdWF0aW9uKDQ1MDgpXEFkZA==?= X-Powered-By: ASP.NET Date: Wed, 15 Oct 2014 20:15:47 GMT Content-Length: 250

{"kBackingField":4508,"kBackingField":{"Id":1,"Name":"Budget - Create Account 1.txt","FileName":"c8bf96b6-cdee-4afc-8ad4-0f52a6710032","Extension":".txt","Type":"form-data"},"kBackingField":1,"kBackingField":1}

HTTP/1.1 200 OK Cache-Control: no-cache Pragma: no-cache Content-Type: application/json; charset=utf-8 Expires: -1 Server: Microsoft-IIS/8.0 DataServiceVersion: 3.0 X-AspNet-Version: 4.0.30319 X-SourceFiles: =?UTF-8?B?QzpcVXNlcnNcZ2Vvcmdlb1xTb3VyY2VcV29ya3NwYWNlc1xGb3JlbnNpY3NcRGJoZGQuRm9yZW5zaWNzXERiaGRkLkZvcmVuc2ljcy5XZWJIb3N0XG9kYXRhXFRpdGxlcw==?= X-Powered-By: ASP.NET Date: Wed, 15 Oct 2014 20:07:21 GMT Content-Length: 202

{ "odata.metadata":"https://localhost:44302/odata/$metadata#Titles","value":[ { "Name":"Mr.","Id":1 },{ "Name":"Mrs.","Id":2 },{ "Name":"Ms.","Id":3 } ] }

From: Jon Samwell [mailto:notifications@github.com] Sent: Wednesday, October 15, 2014 12:59 PM To: jonsamwell/angular-http-batcher Cc: George Olson Subject: Re: [angular-http-batcher] Added OData parsing and relative URLs. (#2)

Is there anything I can read to understand what odata needs for batch requests?

— Reply to this email directly or view it on GitHubhttps://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_jonsamwell_angular-2Dhttp-2Dbatcher_pull_2-23issuecomment-2D59266128&d=AAMCaQ&c=fa_WZs7nNMvOIDyLmzi2sMVHyyC4hN9WQl29lWJQ5Y4&r=B3KJahVz1wyngYqA_Zpz24pE8gP9Q9oX1IO-sTL_HGo&m=WhDANKi1-3gJtjsd3pqWjubeblvr2ZnmgDaWKAOoL_g&s=BpE4lZaWcMb1cKHfhZdFwYIeCv6AiTb2H-SlA-EzCUE&e=.

jonsamwell commented 10 years ago

I think this will be resolved with my latest commits as the json parsing now doesn't just expect a single line.

fabm22 commented 9 years ago

Hi,

I m gonna need a OData adapter which indeed indents the JSON as we can see here : Official OData doc point "2.2 Batch Request Body".
You see it does indent a "changeset_< hash>" into a "batch_< hash>" Example:

--batch_36522ad7-fc75-4b56-8c71-56071383e77b Content-Type: multipart/mixed; boundary=changeset_77162fcd-b8da-41ac-a9f8-9357efbbd621 Content-Length: ###

--changeset_77162fcd-b8da-41ac-a9f8-9357efbbd621 Content-Type: application/http Content-Transfer-Encoding: binary

POST /service/Customers HTTP/1.1 Host: host
Content-Type: application/atom+xml;type=entry Content-Length: ###

_.... more changesets ...._ This probably isn't too hard to write an adapter, but I would like to know **if something was already done for such use case with OData** @georgeolson @jonsamwell (in the idea of this issue)?? Thanks a lot for your help