On Monday, 12 November 2012 23:56:26 UTC, Ning wrote:
> Thanks David.
> I am struggling with how I handle parent child, such as order header,
> line, and shipment. An order line cannot exist outside a header. So we want
> to make the URI something like:
> /orders/123/lines/1/shipments/1
> In the schema, I want to do something like this:
> "orders": {
> "properties": {
> "orderId":...
> "lines": {
> "items": {
> "properties": {
> "lineId":...
> "shipments": {
> "items": {
> "properties" {"shipmentId":...},
> "links": [
> {"rel": "self", "href":
> "/orders/{orderId}/lines/{lineId}/shipments/{shipmentId}"}
> ]
> }
> }
> },
> "links": [
> {"rel": "self", "href": "/orders/{orderId}/lines/{lineId}"}
> ]
> }
> }
> },
> "links":[
> {
> "rel": "self", "href": "/orders/{orderId}"
> }
> ]
> }
> but this is not supported. Is there any alternative?
> Can I reference the parent schema's self link from a child's schema?
> On Saturday, November 10, 2012 4:34:40 AM UTC-8, Geraint (David) wrote:
>> 1. No - you can only reference the immediate properties of an object.
>> 2. According to the version 3 specification, yes. I'm not sure I like
>> it, though - to me, schemas should describe items. However, that's how
>> draft version 3 was written, and I'm not going to try and change it if
>> people find it useful.
>> On Friday, November 9, 2012 8:27:30 PM UTC, Ning wrote:
>>> Thanks for the clarification.
>>> 1. Is it possible to reference the property from the parent schema
>>> inside a nested schema's link? Take my previous example, if I expand it:
>>> "departments": {
>>> "name": "Department",
>>> "properties": {
>>> "departmentId": ...,
>>> "departmentName": ...,
>>> "locationId": {
>>> "type": integer
>>> },
>>> "employees": {
>>> "items": {
>>> "properties": {...},
>>> "links": [
>>> {"rel": "location",
>>> "href": "/locations/{locationId}},
>>> ]
>>> }
>>> }
>>> }
>>> }
>>> Is the location link valid?
>>> 2. Regarding the "instances" link. Using the above example, I can have a
>>> link:
>>> {"rel": "instances",
>>> "href": "/departments"}
>>> for the department schema, and GET /departments is supposed to return a
>>> list of departments. Is it right?
>>> Thanks.
>>> Ning
>>> On Friday, November 9, 2012 1:22:20 AM UTC-8, Geraint (David) wrote:
>>>> A couple of things worth noting: The client is under no obligation to
>>>> believe that the data for the furniture items at the same as the data from
>>>> the claimed URI. It is a useful hint.
>>>> Also, the "self" link is only used because the *complete data* for the
>>>> items of furniture is included, so the client only needs to make one
>>>> request. If you only included a small portion of it, then a "full" link
>>>> would be more appropriate, indicating that the client should visit that URI
>>>> to get the rest of the data.
>>>> On Friday, November 9, 2012 9:18:39 AM UTC, Geraint (David) wrote:
>>>>> The "self" link is often not very useful if you have just fetched the
>>>>> document from that URI. As you say, you already have the URI, so what does
>>>>> the "self" link provide?
>>>>> However, it is more useful when you opened the data from somewhere
>>>>> else, and do *not* know the URI for it. In that case, the "self"
>>>>> link is just a way of specifying that URI from the item data.
>>>>> It's also useful when you have composite data. For instance, say we
>>>>> have this document fetched from /rooms/4:
>>>>> {
>>>>> "roomId": 4,
>>>>> "name": "The lobby",
>>>>> "furniture": [
>>>>> {
>>>>> "furnitureId": 3563,
>>>>> "roomId": 4,
>>>>> "name": "Receptionist's desk",
>>>>> "type": "desk",
>>>>> ...
>>>>> },
>>>>> {
>>>>> "furnitureId": 2031,
>>>>> "roomId": 4,
>>>>> "name": "A wheely chair",
>>>>> "type": "chair",
>>>>> ...
>>>>> },
>>>>> ]
>>>>> }
>>>>> This document contains the *full* details of all the furniture in
>>>>> that room, bundled up inside it. However, if I want to interact with a
>>>>> particular piece of furniture, how do I do that? I could use a JSON
>>>>> Pointer fragment, but then if I moved a piece of furniture from one room to
>>>>> the other, nobody else could tell it was the same piece of furniture.
>>>>> So I define a "self" link on the furniture items:
>>>>> {
>>>>> "title": "Room",
>>>>> "type": "object",
>>>>> "properties": {
>>>>> "furniture": {
>>>>> "type": "array",
>>>>> "items": {
>>>>> "title": "Furniture",
>>>>> "type": "object",
>>>>> "properties": { ... },
>>>>> "links": [
>>>>> * {
>>>>> *
>>>>> * "rel": "self",
>>>>> *
>>>>> * "href": "/furniture/{furnitureId}"
>>>>> *
>>>>> * },
>>>>> *
>>>>> {
>>>>> "rel": "parent",
>>>>> "href": "/room/{roomId}"
>>>>> }
>>>>> ]
>>>>> }
>>>>> }
>>>>> }
>>>>> }
>>>>> Now, if I want to move the wheely chair to another room, I don't have
>>>>> to delete the one in the lobby, and create a new one somewhere else,
>>>>> because this chair has a unique URI of its own. And what's more, I *
>>>>> know* this URI, even though it was served up to me embedded inside
>>>>> another document.
>>>>> So I can probably just modify the chair itself using a PUT request:
>>>>> PUT /furniture/2031
>>>>> {
>>>>> "furnitureId": 2031,
>>>>> "roomId": 15,
>>>>> "name": "The wheely chair from the lobby",
>>>>> "type": "chair",
>>>>> ...
>>>>> }
>>>>> Presumably, the server would at this point stop including the chair in
>>>>> the furniture listing for the lobby (#4), and start including it in a
>>>>> different room (#15).
>>>>> On Thursday, November 8, 2012 11:30:35 PM UTC, Ning wrote:
>>>>>> I am trying to figure out how to use the links for rest APIs.
>>>>>> Suppose that I have a resource /departments and /departments/123 lets
>>>>>> me access a particular department 123.
>>>>>> How will be the self link used by a consumer? say if I have:
>>>>>> "departments": {
>>>>>> "name": "Department",
>>>>>> "properties": {
>>>>>> "departmentId": {
>>>>>> "type": "integer",
>>>>>> "description": "department identifier"
>>>>>> },
>>>>>> "departmentName": {
>>>>>> "type": "string",
>>>>>> "description": "department name"
>>>>>> }
>>>>>> }
>>>>>> "links": [
>>>>>> {
>>>>>> "rel": "self",
>>>>>> "href": "{departmentId}"
>>>>>> }
>>>>>> ]
>>>>>> }
>>>>>> The self link is against a json instance, so I should already have
>>>>>> the instance URI, which is /departments/123. What does the self link
>>>>>> provide?