diff --git a/README.md b/README.md index bdef40c..0dc8c2d 100644 --- a/README.md +++ b/README.md @@ -152,3 +152,22 @@ This is the recommended test servers: The nanopublications can then be queried from this test SPARQL endpoint: - https://virtuoso.test.nps.knowledgepixels.com/sparql + + +## Response + +The response to the HTTP request consists of a simple JSON structure, according to this schema: + +{ + "id": "https://w3id.org/np/RA...", + "url": "https://.../RA..." +} + +The value for "id" is the unique IRI identifier of the nanopublication. This should be used for references, including for pointing to the nanopublication in SPARQL endpoints. + +The value for "url" is the place where the nanopublication was published. The nanopublication is available at that location immediately. + +Running an HTTP request against the "id" value will forward to a URL where the nanopublication is served, which might be the one of the "url" value or a different one in the network. +This forwarding might not work immediately, but can take a few seconds or a minute. + +If a testing server is used, forwarding of the "id" value doesn't work, as the nanopublication is not added to the network, but the "url" value points to the test server and does resolve. diff --git a/dependency-reduced-pom.xml b/dependency-reduced-pom.xml index 633c90a..d1e9817 100644 --- a/dependency-reduced-pom.xml +++ b/dependency-reduced-pom.xml @@ -3,7 +3,7 @@ 4.0.0 com.knowledgepixels nanopub-http - 1.3-SNAPSHOT + 1.4-SNAPSHOT https://github.com/knowledgepixels/nanopub-http @@ -60,7 +60,7 @@ io.vertx vertx-junit5 - 4.4.5 + 4.5.1 test @@ -72,7 +72,7 @@ org.junit.jupiter junit-jupiter-api - 5.10.0 + 5.10.1 test @@ -92,7 +92,7 @@ org.junit.jupiter junit-jupiter-engine - 5.10.0 + 5.10.1 test @@ -127,9 +127,9 @@ com.knowledgepixels.nanopub.http.MainVerticle 3.5.0 3.11.0 - 4.4.5 + 4.5.1 io.vertx.core.Launcher - 5.10.0 + 5.10.1 3.1.2 UTF-8 3.1.0 diff --git a/pom.xml b/pom.xml index fb5281a..96654a6 100644 --- a/pom.xml +++ b/pom.xml @@ -18,8 +18,8 @@ 3.1.2 3.1.0 - 4.4.5 - 5.10.0 + 4.5.1 + 5.10.1 com.knowledgepixels.nanopub.http.MainVerticle io.vertx.core.Launcher @@ -80,7 +80,7 @@ org.nanopub nanopub - 1.52 + 1.55 org.apache.commons diff --git a/src/main/java/com/knowledgepixels/nanopub/http/MainVerticle.java b/src/main/java/com/knowledgepixels/nanopub/http/MainVerticle.java index a19146a..0b3a5de 100644 --- a/src/main/java/com/knowledgepixels/nanopub/http/MainVerticle.java +++ b/src/main/java/com/knowledgepixels/nanopub/http/MainVerticle.java @@ -97,13 +97,17 @@ public void start(Promise startPromise) throws Exception { np = SignNanopub.signAndTransform(np, c); } + String npId; if (req.getParam("server-url") == null) { - PublishNanopub.publish(np); + npId = PublishNanopub.publish(np); } else { - publishToServer(np, req.getParam("server-url")); + String serverUrl = req.getParam("server-url"); + publishToServer(np, serverUrl); + npId = serverUrl + TrustyUriUtils.getArtifactCode(np.getUri().stringValue()); } System.err.println("PUBLISHED: " + np.getUri()); - req.response().setStatusCode(HttpStatus.SC_OK).putHeader("content-type", "text/plain").end(np.getUri().stringValue() + "\n"); + String responseJson = "{\n \"id\": \"" + np.getUri().stringValue() + "\",\n \"url\": \"" + npId + "\"\n}\n"; + req.response().setStatusCode(HttpStatus.SC_OK).putHeader("content-type", "application/json").end(responseJson); } catch (Exception ex) { req.response().setStatusCode(HttpStatus.SC_BAD_REQUEST).setStatusMessage(ex.getMessage()).end("Error: " + ex.getMessage() + "\n"); ex.printStackTrace();