diegomvh / angular-odata

Client side OData typescript library for Angular
https://www.npmjs.com/package/angular-odata
MIT License
46 stars 14 forks source link

Query in request body option? #45

Closed JurgenCruz closed 2 years ago

JurgenCruz commented 2 years ago

Hi, I had a question. I need to consume a service that uses OData, but for some reason they are expecting the query in the request body instead of the query parameter. This appears to be supported in the standard: https://devblogs.microsoft.com/odata/passing-odata-query-options-in-the-request-body/ But wanted to know if your library has a way of consuming this way.

Thanks.

diegomvh commented 2 years ago

Hello @SuperJugy Thank you for considering the library and your issue.

I saw this possibility in the specifications a year ago and since my backend (own development) does not require this feature, I did not include anything about it Today thinking about the necessary modifications to be able to use post in the queries I think it is not complex to do it. It remains to define if this is something transversal to the entire api or only for some queries. In the blog post it's said that it is possible to mix parameters, part in the query string and part in the body ... I don't know whether to allow this behavior or to work with an all or nothing approach Any help or opinion is welcome. The changes in the code are not so many, the "complicated" thing is to see how to approach them without having a test backend. Regards

JurgenCruz commented 2 years ago

In my specific scenario I need everything in the request. But I guess having the flexibility would be better for future users that need it.

I unfortunately cannot help with a test backend, since we are working with a closed source. And my team didn't even work on the backend part.

diegomvh commented 2 years ago

Hi @SuperJugy New in versión 0.78.0... For global use bodyQueryOptions. ApiConfig in they section options. For custom query use bodyQueryOptions for each fetch method as a parameter. Regards

JurgenCruz commented 2 years ago

Thanks!

Ipri commented 2 years ago

Hi, @diegomvh. I try to use "bodyQueryOptions" and it put query params into body of POST request. But I don't see "$query" word in URl as described on http://docs.oasis-open.org/odata/odata/v4.01/odata-v4.01-part2-url-conventions.html#sec_PassingQueryOptionsintheRequestBody I found getter in sources, but it looks like it's not used get path() { return this._queryBody ?${this._path}/${$QUERY}: this._path; } Please, tell how it should works

diegomvh commented 2 years ago

Hi @Ipri You have found an error within the code. This feature has not been extensively tested since its initial implementation. Create some tests to test the basic options of using $query by setting the api options or on each request.

https://github.com/diegomvh/angular-odata/blob/cdb2b8cbc2d51c0adc7af7c49016d402b0c0f37c/projects/angular-odata/src/lib/client.spec.ts#L533

I hope it helps, these changes are for the next version (0.102.0 I guess) of the library. Thank you very much for your issue report.

Ipri commented 2 years ago

Thank and you! I`ll hope next version will be soon)