Skip to content

Commit

Permalink
Return ID/URL pair as JSON instead of just ID as plain text
Browse files Browse the repository at this point in the history
  • Loading branch information
tkuhn committed Dec 15, 2023
1 parent 5323610 commit 60f442b
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 12 deletions.
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
12 changes: 6 additions & 6 deletions dependency-reduced-pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.knowledgepixels</groupId>
<artifactId>nanopub-http</artifactId>
<version>1.3-SNAPSHOT</version>
<version>1.4-SNAPSHOT</version>
<url>https://github.com/knowledgepixels/nanopub-http</url>
<build>
<plugins>
Expand Down Expand Up @@ -60,7 +60,7 @@
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-junit5</artifactId>
<version>4.4.5</version>
<version>4.5.1</version>
<scope>test</scope>
<exclusions>
<exclusion>
Expand All @@ -72,7 +72,7 @@
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.10.0</version>
<version>5.10.1</version>
<scope>test</scope>
<exclusions>
<exclusion>
Expand All @@ -92,7 +92,7 @@
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.10.0</version>
<version>5.10.1</version>
<scope>test</scope>
<exclusions>
<exclusion>
Expand Down Expand Up @@ -127,9 +127,9 @@
<main.verticle>com.knowledgepixels.nanopub.http.MainVerticle</main.verticle>
<maven-shade-plugin.version>3.5.0</maven-shade-plugin.version>
<maven-compiler-plugin.version>3.11.0</maven-compiler-plugin.version>
<vertx.version>4.4.5</vertx.version>
<vertx.version>4.5.1</vertx.version>
<launcher.class>io.vertx.core.Launcher</launcher.class>
<junit-jupiter.version>5.10.0</junit-jupiter.version>
<junit-jupiter.version>5.10.1</junit-jupiter.version>
<maven-surefire-plugin.version>3.1.2</maven-surefire-plugin.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<exec-maven-plugin.version>3.1.0</exec-maven-plugin.version>
Expand Down
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
<maven-surefire-plugin.version>3.1.2</maven-surefire-plugin.version>
<exec-maven-plugin.version>3.1.0</exec-maven-plugin.version>

<vertx.version>4.4.5</vertx.version>
<junit-jupiter.version>5.10.0</junit-jupiter.version>
<vertx.version>4.5.1</vertx.version>
<junit-jupiter.version>5.10.1</junit-jupiter.version>

<main.verticle>com.knowledgepixels.nanopub.http.MainVerticle</main.verticle>
<launcher.class>io.vertx.core.Launcher</launcher.class>
Expand Down Expand Up @@ -80,7 +80,7 @@
<dependency>
<groupId>org.nanopub</groupId>
<artifactId>nanopub</artifactId>
<version>1.52</version>
<version>1.55</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
Expand Down
10 changes: 7 additions & 3 deletions src/main/java/com/knowledgepixels/nanopub/http/MainVerticle.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,17 @@ public void start(Promise<Void> 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();
Expand Down

0 comments on commit 60f442b

Please sign in to comment.