json-ld / json-ld.org

JSON for Linked Data's documentation and playground site
https://json-ld.org/
Other
859 stars 152 forks source link

how can we describe a available operations for a specific api in json-ld? #666

Closed videni closed 4 years ago

videni commented 6 years ago

for example, when user try to view a resource , the client might show an edit button when user has edit permission.HAL has links, how can we do this in jsonld?

elf-pavlik commented 6 years ago

You might find http://www.hydra-cg.com/ interesting, it uses JSON-LD to express hypermedia controls in web APIs. One of the JSON-LD 1.0 editors started and still leads this effort.

BigBlueHat commented 6 years ago

@videni in addition to Hydra, you can also use HAL or any other JSON-based hypermedia format alongside the JSON-LD bits. The difference would be that by default (at least) HAL _links (etc) would not be mapped into the output graph built from processing the JSON-LD. Whether that's good or not depends on your use case.

At Wiley, we've mixed HAL and JSON-LD together successfully. The HAL bits are deliberately (in our case) not part of the JSON-LD @context (and therefore not part of the input or output graphs). This allows us to augment the JSON-LD data and still provide hypermedia affordances within the JSON. It makes for a nice 🍸. 😄

videni commented 6 years ago

@elf-pavlik , I am using ApiPlatform, it supports json-ld and HAL together , I don't find any documents in hydra-cg that describe _links equivalent in HAL. will json-ld cover this use case in the future?

@BigBlueHat, good idea, thanks for sharing.

elf-pavlik commented 6 years ago

This section shows usage of hydra:Link http://www.hydra-cg.com/spec/latest/core/#adding-affordances-to-representations

Possibly this comparison of formats can also come useful: https://dracoblue.net/dev/overview-of-json-hypermedia-link-formats/

for example, when user try to view a resource , the client might show an edit button when user has edit permission.HAL has links, how can we do this in jsonld?

You can find example of expressing edit operation in Hydra here: https://github.com/HydraCG/Specifications/blob/master/drafts/use-cases/6.updating-event.md

In that case it describes making HTTP PUT request to the same resource, so it actually doesn't link to any other resource and would not use hydra:Link