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

Feature/import api #88

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Open

Feature/import api #88

wants to merge 13 commits into from

Conversation

bplatz
Copy link
Contributor

@bplatz bplatz commented Aug 22, 2024

This adds a new 'import' API to fluree/server which accepts TURTLE (.ttl) and JSON-LD.

The main feature of this is that raw RDF data can be imported without converting it to JSON-LD... and even raw JSON-LD can be imported without having to reformat it by wrapping your JSON-LD file in {"insert": }.

The RDF data is just sent in the HTTP body, regardless of format.

API endpoint:

<server>/fluree/import

To use the new API with TURTLE, the HTTP Headers must include:

{"Content-Type":  "text/turtle",
 "Fluree-Ledger": "<fluree-ledger-name-here>"}

To use the API with JSON-LD, the HTTP Headers must include:

{"Content-Type":  "application/json",
 "Fluree-Ledger": "<fluree-ledger-name-here>"}

For now, the ledger must already exist, and you are just 'importing' into an existing ledger. Having the ability to create a new ledger from an import is likely desirable, and it can be added fairly simply.

@bplatz bplatz requested a review from a team August 22, 2024 13:50
req* (assoc req :body-params subject :credential/did did :raw-txn body-params)]
(log/debug "Unwrapped credential with did:" did)
(handler req*))))
(if (#{"application/json" "application/jwt"} content-type)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to sign a turtle import? I think you'd use a JWT, but cred/verify will not handle turtle correctly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think so, but it wasn't the priority and I think there is a good chance this middleware dissapears, but not 100% on that.

The db api now has *-credential APIs which ideally we'd mostly leverage instead of fluree/server doing its own thing.

But for now it doesn't have signatures for TTL imports, although I should make a ticket for it as I think it should at some point.

(m/schema [:or
[:string {:min 1}]
[:map-of :any :any]
[:sequential map?]]))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just checking to make sure I understand, these schemas correspond to:

  • turtle string
  • json-ld map
  • vector of json-ld maps

Is that right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, correct.

In this case we are doing a validation that doesn't offer much value, but it is how things are set up. I don't know how to bypass it, but would rather we did.

For example, here we have to look at every element of a json-ld vector and check map?. But in a moment we'll be running json-ld/expand which does the same check (and more). Not a big deal for a small tx, but meaningful for a very large one.

Or, with ttl, it has to perform a (count ttl) on potentially a large file to make sure it is > 1, but then we turn around and run it through a ttl import which would throw anyhow if malformed.

In some cases these validations seem to offer a lot of value, but in this case it just slows things down from what I can tell.

Copy link
Contributor

@dpetran dpetran left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we should name this add instead of import, sort of mirroring the SPARQL Update API. It leaves room for us to follow those conventions for other graph-level operations. We already have create, we could add copy, move, and drop as well, operations that I think could be especially useful for doing git-like branching workflows, or moving graphs between different types of storage.

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

Successfully merging this pull request may close these issues.

2 participants