Server.js icon indicating copy to clipboard operation
Server.js copied to clipboard

Allow to PUT fragments in MemoryDatasource

Open thgh opened this issue 9 years ago • 12 comments
trafficstars

I foresee these changes:

  • Allow PUT in LinkedDataFragmentsServer.js#L57
  • Add controller that responds to PUT
  • Loop over parsed request data and call this._datasources[query.datasource].datasource.addTriple

Do you think I will encounter other obstacles?

thgh avatar Jun 28 '16 21:06 thgh

Looks good, but:

  • What will the HTTP interface look like? I.e., to what resource do you PUT?
  • Be sure to provide an addTriple stub in the generic Datasource (which should throw an exception)
  • Be sure to only loop over data that is in the default graph (if a quad representation is received)

RubenVerborgh avatar Jun 28 '16 21:06 RubenVerborgh

I implemented something similar in the past with in a hackish way by adding POST over here: https://github.com/LinkedDataFragments/Server.js/blob/master/lib/LinkedDataFragmentsServer.js#L49 and just writing the triples to a file, which then can be read by a datasource. Mind that in this case POST makes more sense than PUT as the request is not idempotent: you "add" triples to the existing collection of triples.

pietercolpaert avatar Jun 29 '16 11:06 pietercolpaert

I also implemented this a while ago (in a less hackish way ;-) ) I pushed it to the feature-insert branch, it starts from 6ca4aca2678c08fb549724e3905a554214750728. The branch is a bit behind on the master, so there might be some minor conflicts.

Take into account that this currently has no authentication checks, this means that everyone will be able to insert data using a POST.

rubensworks avatar Jun 29 '16 14:06 rubensworks

@pietercolpaert Since the repeated addition of the same triples results in the same as having them one time, I'd argue that it is idempotent (blank nodes aside). However, PUT is a replacement operation, not an addition, so that would be the main problem.

RubenVerborgh avatar Jun 29 '16 17:06 RubenVerborgh

I'd a argue that it isn't idempotent as each POST triggers a new context. E.g., if I have a sensor that sends out the temperature, I can POST the temperature each second. There will be a lot of the same triples yet each second the time context has changed and it is relevant to store this POST action of adding triples under a new id chosen by the server.

But on topic: I think that having a strategy to POST triples should also contain the cross cutting concern of authentication and maybe even authorisation. Any idea of existing npm libs for this?

pietercolpaert avatar Jun 30 '16 06:06 pietercolpaert

Idempotence depends on server implementation; if it is just inserts in a triple store (as I assumed), it is idempotent (blank nodes aside). Other implementations might do other things, such as attaching a timestamp, which make the operation non-idempotent.

Authentication: regardless of libs, we should first decide on HTTP level what happens.

RubenVerborgh avatar Jun 30 '16 17:06 RubenVerborgh

@mielvds Is it possible to use your WebID implementation for this?

rubensworks avatar Jun 30 '16 17:06 rubensworks

I suggest PUT /mygraph?subject=http://... which would

  • Delete triples from mygraph that match the query
  • Add input triples to mygraph (or only those that match the query?)

POST /mygraph should probably also be available.

thgh avatar Jul 02 '16 20:07 thgh

@thgh Both options are good. Open question: what about POST to more specific fragments?

Also, how will we deal with blank nodes (especially regarding deletion and addition)? I think skolemization is the way to go.

RubenVerborgh avatar Jul 03 '16 01:07 RubenVerborgh

@rubensworks yes, it would. Although no authorization layer has been implemented yet.

mielvds avatar Jul 04 '16 08:07 mielvds

Has anything more been done on this?

jacoscaz avatar Oct 07 '17 15:10 jacoscaz

Not yet, still focusing on read. For read/write solutions, you might be interested in Solid, and the TPF solution I built on top of it.

RubenVerborgh avatar Oct 07 '17 19:10 RubenVerborgh