jonsamwell / angular-http-batcher

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

OData adapter needed #31

Open fabm22 opened 8 years ago

fabm22 commented 8 years ago

Hi, I hope I don't seem too aggressive but I dare to kinda repost my message here, instead as a comment in the issue #2 . This really would be a great addition as a feature, to have an OData adapter


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 ??

Thanks a lot for your help

jonsamwell commented 8 years ago

Hi @fabm22

Yeah it would be great to get a OData adapter in. You are right it isn't to hard to do but it would be really really really helpful and speed the process along if you could provide a sample OData server implementation that I could code against.

https://github.com/jonsamwell/angular-http-batcher/tree/master/servers

Alternatively, if you want to write it feel free to ask me any questions. The best place to start would be to look at the current HTTP Batch adapter as it probably will not be too far removed from it.

https://github.com/jonsamwell/angular-http-batcher/blob/master/src/services/adapters/httpAdapter.js

Thanks,

Jon

kerzner commented 8 years ago

@fabm22 I'm looking into writing an odata adapter for this. How would you handle the preflight check for odata batch requests?

My understanding is that an OData batch request is a POST with "Content-Type: multipart/mixed." This content type needs a preflight OPTIONS request. But the OData reference services do not allow OPTIONS. They reply with a status code 501--not implemented.

I think this gives us two options: 1) skip the preflight check or 2) modify the OData service to respond correctly to OPTIONS. Both of these feel like hacks though. Which one seems like the better option? Is there another way to do this?

jonsamwell commented 8 years ago

@kerzner It will only need a preflight request if the request is coming from a different domain than the callee. The browser will handle this so you have no control over it.

fabm22 commented 8 years ago

@kerzner @jonsamwell From my little experience, yes the aspect of preflight is mainly handled for CORS ( https://en.wikipedia.org/wiki/Cross-origin_resource_sharing ) scenarios , ie. calls between different domains. In our case we use a proxy server to always have the same domain.

And for your question, I would go (1), skip the preflight altogether, given if you use an OData Service, it is _implied_ that you will use multipart/mixed as Content-Type for a batch operation

"Batch requests allow grouping multiple operations, as described in [OData:Core], into a single HTTP request payload. A batch request MUST be represented as a Multipart MIME v1.0 message [RFC2046], a standard format allowing the representation of multiple parts"

src : http://www.odata.org/documentation/odata-version-3-0/batch-processing/

kerzner commented 8 years ago

Thank you both for the info. It sounds like the preflight check cannot be skipped as it is handled by the browser. I need to figure out how to get my odata server to respond to the OPTIONS request correctly. This is not really related to creating an odata adapter for this project though.

@fabm22 did you ever write an adapter for this? what did you end up doing with your batch requests?

jonsamwell commented 8 years ago

@kerzner any progress on this?

kerzner commented 8 years ago

No. I don't have a reference odata service to develop with. I had planned to add an OData endpoint to your WebApiHttpBatchServer, but I can't get the demo working locally. I might not be using it right though.

Here's what I've done:

  1. I ran the WebApiHttpBatchServer.sln in Visual Studio 2015 - this runs at http://localhost:8080/
  2. I then created a webstorm project using your repo, installing the dependencies with bower.
  3. I ran the example/index.html using webstorm. This runs at http://localhost:63342/angular-http-batcher/example/index.html
  4. When I click the 'call singe api' button, this is the error that I get: image

Like I said, I'm probably doing something wrong, but I don't know what. I don't have much experience with web services.

Any ideas?