Closed georgeolson closed 10 years ago
Thanks for this! Could you provide a couple of tests for this behavior?
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=.
Awesome!
Is there anything I can read to understand what odata needs for batch requests?
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
{"
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=.
I think this will be resolved with my latest commits as the json parsing now doesn't just expect a single line.
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: ###
It's not clean, but it allows relative service URLs and parses OData responses.