janhommes / o.js

o.js - client side oData lib.
https://janhommes.github.io/o.js/example/
MIT License
241 stars 58 forks source link

@odata.nextLink support #24

Closed IceOnFire closed 5 years ago

IceOnFire commented 8 years ago

Hi @janhommes,

I'm not sure of what I'm about to say here, but when I perform a request to an OData service without specifying any page size I get an additional field in the response that tells me what to do next:

http://services.odata.org/V4/Northwind/Northwind.svc/Orders

{
  ...
  "@odata.nextLink": "Orders?$skiptoken=10447"
}

Is there a way already to get this info inside the oHandler? How could we add it in case? Thanks in advance,

Antony

janhommes commented 8 years ago

Hey @IceOnFire,

take a look at 8feb80a. I added a raw property to the oHandler, that does only the JSON parsing but does not remove the additional meta data. I will leave this defect open, because this needs some improvement. For example I do not like the property name raw. It is not real raw data because it is already parsed to JSON. Maybe we need to properties, one parsed and one raw.

regards Jan

IceOnFire commented 8 years ago

Personally I don't mind the term raw: parsing is such a trivial and necessary activity that you could take it as an implicit step.

While studying the Flux/Redux architecture I stumbled upon the Flux Standard Action specification. Maybe we could take inspiration from there for the naming: data is stored in the payload, metadata in a meta property.

This leads me however to propose breaking changes: the data array could be payload.results, inlinecount becomes payload.total. Just thinking out loud.

janhommes commented 8 years ago

Yeah I thought about this one as well. It is something we should change in the next version 0.3.0:

IceOnFire commented 8 years ago

Nope, I can't come up with better ideas :grin:

be236 commented 7 years ago

Yes, I would like to see all those possible fields returned:

payload.data - would rename this one because it could be one, or more results. Any better naming idea? payload.total - only if inlinecount is set payload.raw - the raw data payload.meta - only the @ metadata

be236 commented 7 years ago

I looked inside o.js file and don't see any mention of "payload" or "payload.raw," etc.

Can you tell me where it is and an example of how to access that raw payload back?

janhommes commented 7 years ago

Sorry, the raw property is just in the branch mentioned above. If you check that out you can use it by calling this.raw. I will try to make a new version in a couple of days and include the raw property there.

be236 commented 7 years ago

Hopefully we can get this code in that branch merged into Master, so when I do "git clone" on this repo, I'll get all these changes.

Also, will this.raw return me the RESPONSE HEADERS too?

janhommes commented 7 years ago

this.raw included in last release. https://github.com/janhommes/o.js/tree/v0.3.7

janhommes commented 5 years ago

83