Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Manage all content negociation on API services #1226

Open
srosset81 opened this issue Jan 9, 2024 · 7 comments
Open

Manage all content negociation on API services #1226

srosset81 opened this issue Jan 9, 2024 · 7 comments

Comments

@srosset81
Copy link
Contributor

srosset81 commented Jan 9, 2024

Problem

Turtle handling is broken for a long time (see #995). It's complicated to deal with several formats on the LdpService and TripleStoreService. Plus it's annoying to have to declare a contentType or accept param for every calls (see #542)

Proposal

We should make it a rule that Moleculer services only handle JSON-LD data, because JSON is a first-class citizen on Moleculer, and more generally on javascript.

This means it is the responsibility of API services (we have a new, very functional LdpApiService) or actions to transform data from/to Turtle, before handing it to Moleculer services as JSON-LD. This means the TripleStoreService will not need to worry about content negociation anymore.

This way we can clean up the LdpService and TripeStoreService while fixing the Turtle handling.

We will need to add tests for the Turtle format, as none exist at the moment.

@srosset81
Copy link
Contributor Author

srosset81 commented Jan 10, 2024

The main issue will be to find a good library to transform from/to JSON-LD, where performances are good. If we could directly use the correct JSON-LD context, that would be great.

There are some answers here:
digitalbazaar/jsonld.js#255
https://forum.solidproject.org/t/is-there-a-converter-between-json-ld-and-turtle-n3/1817/2

The most stable libraries all use the same Sink interface: https://rdf.js.org/#sink-interface. One solution could be to use https://github.com/rdfjs-base/parser-jsonld to parse JSON-LD to RDF.js quads, and then https://github.com/rdfjs-base/serializer-turtle to serialize RDF.js quads to Turtle. Haven't found a Turtle parser though...

https://github.com/rdfjs/N3.js is not a good candidate since it doesn't support JSON-LD.

@simonLouvet
Copy link
Contributor

I don't have any objections, but I'm afraid it will greatly reduce performance if an application wants to communicate with the server in turtle mode.

@srosset81
Copy link
Contributor Author

Is there any app, in the past 4 years, which has been using Turtle instead of JSON-LD ?
I guess not, since the Turtle format hasn't been working for a long time.

@simonLouvet
Copy link
Contributor

I agree with the statement about usage.
I think we need to clarify/document this on semapps.org and in our communications to avoid any misunderstandings.
Semapps can handle formats other than json-ld at the expense of a loss of performance (to be quantified). This is not a prerequisite for moving forward, just a desire for transparency in the future.

@srosset81
Copy link
Contributor Author

We could maybe use the new JSONExt serializer to transform Turtle to JSON-LD
https://github.com/moleculerjs/moleculer/releases/tag/v0.15.0-beta1

@Laurin-W
Copy link
Contributor

We could create middleware functions for the api.addRoute registrations.
This can give as the flexibility of supporting transparent content-negotiation for different rdf content types and accept types (where desired).
Since we are going to create shapes for ldo object creation and validation, we can create middlewares for that use cases too. This way we will be able to created custom routes and controlled container mixins that come with type safety

I agree that we should keep an eye on performance (a general thing that we can improve on!). I'm not too worried though, my intution says that multiple round-trip-times between db and backend are by far the greater slow-down (happy to be disproven though :) ).

@Laurin-W
Copy link
Contributor

We might even be able to use this to support dereferncing resources linked with certain predicates / join it with the DereferenceMixin.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants