janhommes / o.js

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

WIP: Support for GET queries using `.ref` #63

Closed zhevron closed 3 years ago

zhevron commented 6 years ago

Originally requested by @be236 in #51

Suggested API:

o('Products(0)').ref('Categories').get(result => console.log(result.data));

Relevant part of the v4 spec:

11.2.7 Requesting Entity References
To request entity references in place of the actual entities, the client issues a GET request with /$ref appended to the resource path.
If the resource path does not identify an entity or a collection of entities, the service returns 404 Not Found.
If the resource path terminates on a collection, the response MUST be the format-specific representation of a collection of entity references pointing to the related entities. If no entities are related, the response is the format-specific representation of an empty collection.
If the resource path terminates on a single entity, the response MUST be the format-specific representation of an entity reference pointing to the related single entity. If the resource path terminates on a single entity and no such entity exists, the service returns either  204 No Content or 404 Not Found.
Example 61: collection with an entity reference for each Order related to the Product with ID=0

http://host/service/Products(0)/Orders/$ref

See: http://docs.oasis-open.org/odata/odata/v4.0/errata03/os/complete/part1-protocol/odata-v4.0-errata03-os-part1-protocol-complete.html#_Toc453752290

Relevant part of the v3 spec:

10.2.4. Requesting $links between Entities
To request the links (URLs) of related entities according to a particular relationship, the client issues a GET request.

The path of the request is /$links/ appended to the path of a the source entity’s request URL, followed by the name of the navigation property representing the relationship.

On success, the response body MUST contain the URL for each related entity, formatted as a either a single link, or a collection of links, depending on the cardinality of the relationship.

If the navigation property does not exist on the entity indicated by the request URL, the service SHOULD return 404 Not Found.

For example:

http://services.odata.org/OData/OData.svc/Products(0)/$links/Orders
Returns the URLs of each Order related to the Product with ID=0.

See: http://www.odata.org/documentation/odata-version-3-0/odata-version-3-0-core-protocol/

zhevron commented 6 years ago

I'll wait for #60 to land before I tackle this one.