Skip to content

Open Saber API Examples

jyotsna-tarento edited this page Apr 18, 2018 · 9 revisions

Open Saber API Examples

1. Create

This API creates a new entity in the registry.

POST - /create

Request Body


{
	"id": "open-saber.registry.create",
	"ver": "1.0",
	"ets": "11234",
	"params": 
	{
		"did": "",
		"key": "",
		"msgid": ""
	},

	"request": 
	{
		"@context": 
		{
			"rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
			"rdfs": "http://www.w3.org/2000/01/rdf-schema#",
			"book": "http://example.com/voc/book/1.0.0/",
			"xsd": "http://www.w3.org/2001/XMLSchema#",
			"@vocab": "http://example.com/voc/book/1.0.0/",
		},

		"@type": "Book",
		"bookCode": 12345,
		"authorName": "JK Rowling",
		"title": "Harry Potter",
		"publisher": "Times Publishing",
		"tags": ["hogwarts","childrens' book","series"],
		"genre":["fantasy"],
		"reviews": [
		{
			"@type": "Review",
			"reviewComment": "Very exciting and fun-filled",
			"reviewerName": "John doe"
		},
		{
			"@type": "Review",
			"reviewComment": "Takes you to a magical world",
			"reviewerName": "Jane doe"
		}
		],
		"releaseYear":{
				"@type": "xsd:gYear",
				"@value": "2000"
		},
		"languages":["LanguageCode-ENGLISH"]
	}
}

Response

{
  "id": //identifier , e.g. "open-saber.registry.create",
  "ver": //version "1.0",
  "ets": //epoch timestamp in format "YYYY-MM-DDThh:mm:ssZ+/-nn.nn",
  "params": {
    "resmsgid": "",
    "msgid": "",
    "err": "",
    "status": "successful",
    "errmsg": ""
  },
  "result": {              
     "entity": "http://example.com/voc/book/1.0.0/38e57c47-3bf5-4320-a94c-de1ad98c5387"
  }
}

2. Read

This API is used to read an entity from the registry using the identifier of the entity.

GET - /read?iri=http://example.com/voc/book/1.0.0/38e57c47-3bf5-4320-a94c-de1ad98c5387

Response Body


{
	"id": "open-saber.registry.read",
	"ver": "1.0",
	"ets": "11234",
	"ets": 1523634351,
    	"params": {
        	"resmsgid": "",
        	"msgid": "016c7abc-0bfb-432d-8a15-0caaccadef9d",
        	"err": "",
        	"status": "SUCCCESSFUL",
        	"errmsg": ""
    	},
    	"responseCode": "OK",
    	"result": {
	    "@context": 
		{
			"rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
			"rdfs": "http://www.w3.org/2000/01/rdf-schema#",
			"book": "http://example.com/voc/book/1.0.0/",
			"xsd": "http://www.w3.org/2001/XMLSchema#",
			"@vocab": "http://example.com/voc/book/1.0.0/",
			"language":{
				"@type":"@id"
			},
			"genre":{
				"@type":"@id"
			}
		},
            "@graph": [
		"@id": "book:38e57c47-3bf5-4320-a94c-de1ad98c5387",
		"@type": "Book",
		"bookCode": 12345,
		"authorName": "JK Rowling",
		"title": "Harry Potter",
		"publisher": "Times Publishing",
		"tags": ["hogwarts","children's book","series"],
		"genre":["BookTypeCode-FANTASY"],
		"reviews": [
		{
			"@id": "book:38e57c47-3bf5-4320-a94c-de1ad98c5388",
			"@type": "Review",
			"reviewComment": "Very exciting and fun-filled",
			"reviewerName": "John doe"
		},
		{
			"@id": "book:38e57c47-3bf5-4320-a94c-de1ad98c5389",
			"@type": "Review",
			"reviewComment": "Takes you to a magical world",
			"reviewerName": "Jane doe"
		}
		],
		"releaseYear":{
				"@type": "xsd:gYear",
				"@value": "2000"
		},
		"language":"LanguageCode-ENGLISH"
		]
	}
}

3. Update

This API is used to target and update any entity by using the identifier of the entity in the database.

Case 1

Updating a few properties such as title and bookCode for the book.

POST - /update

Request Body


{
	"id": "open-saber.registry.update",
	"ver": "1.0",
	"ets": "11234",
	"params": 
	{
		"did": "",
		"key": "",
		"msgid": ""
	},

	"request": 
	{
		"@context": 
		{
			"rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
			"rdfs": "http://www.w3.org/2000/01/rdf-schema#",
			"book": "http://example.com/voc/book/1.0.0/",
			"xsd": "http://www.w3.org/2001/XMLSchema#",
			"@vocab": "http://example.com/voc/book/1.0.0/",
		},
		"@id": "book:38e57c47-3bf5-4320-a94c-de1ad98c5387", //identifier should point to the IRI of the book entity/node to be updated
		"bookCode": 12345,
		"title": "Harry Potter and the Half Blood Prince"
	}
}

Response

{
  "id": //identifier , e.g. "open-saber.registry.update",
  "ver": //version "1.0",
  "ets": //epoch timestamp in format "YYYY-MM-DDThh:mm:ssZ+/-nn.nn",
  "params": {
    "resmsgid": "",
    "msgid": "",
    "err": "",
    "status": "successful",
    "errmsg": ""
  },
  "result": {}
}

Case 2

Updating properties such as reviewComments of an existing review for the book.

POST - /update

Request Body


{
	"id": "open-saber.registry.update",
	"ver": "1.0",
	"ets": "11234",
	"params": 
	{
		"did": "",
		"key": "",
		"msgid": ""
	},

	"request": 
	{
		"@context": 
		{
			"rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
			"rdfs": "http://www.w3.org/2000/01/rdf-schema#",
			"book": "http://example.com/voc/book/1.0.0/",
			"xsd": "http://www.w3.org/2001/XMLSchema#",
			"@vocab": "http://example.com/voc/book/1.0.0/"
		},
		"@id": "book:38e57c47-3bf5-4320-a94c-de1ad98c5388", //identifier should point to the IRI of the review entity/node to be updated within the book
		"reviewComment": "Very exciting and entertaining"
	}
}

Response

{
  "id": //identifier , e.g. "open-saber.registry.update",
  "ver": //version "1.0",
  "ets": //epoch timestamp in format "YYYY-MM-DDThh:mm:ssZ+/-nn.nn",
  "params": {
    "resmsgid": "",
    "msgid": "",
    "err": "",
    "status": "successful",
    "errmsg": ""
  },
  "result": {}
}

Case 3

Updating properties such as language of a book.

POST - /update

Request Body


{
	"id": "open-saber.registry.update",
	"ver": "1.0",
	"ets": "11234",
	"params": 
	{
		"did": "",
		"key": "",
		"msgid": ""
	},

	"request": 
	{
		"@context": 
		{
			"rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
			"rdfs": "http://www.w3.org/2000/01/rdf-schema#",
			"book": "http://example.com/voc/book/1.0.0/",
			"xsd": "http://www.w3.org/2001/XMLSchema#",
			"@vocab": "http://example.com/voc/book/1.0.0/",
			"language":{
				"@type":"@id"
			},
		},
		"@id": "book:38e57c47-3bf5-4320-a94c-de1ad98c5387", //identifier should point to the IRI of the book entity/node to be updated
		"language":"LanguageCode-FRENCH"
	}
}

Response

{
  "id": //identifier , e.g. "open-saber.registry.update",
  "ver": //version "1.0",
  "ets": //epoch timestamp in format "YYYY-MM-DDThh:mm:ssZ+/-nn.nn",
  "params": {
    "resmsgid": "",
    "msgid": "",
    "err": "",
    "status": "successful",
    "errmsg": ""
  },
  "result": {}
}

Case 4

Updating properties such as tags of a book. When one or more values are sent for this field, the existing value for the field gets updated/replaced with these new values.

POST - /update

Request Body


{
	"id": "open-saber.registry.update",
	"ver": "1.0",
	"ets": "11234",
	"params": 
	{
		"did": "",
		"key": "",
		"msgid": ""
	},

	"request": 
	{
		"@context": 
		{
			"rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
			"rdfs": "http://www.w3.org/2000/01/rdf-schema#",
			"book": "http://example.com/voc/book/1.0.0/",
			"xsd": "http://www.w3.org/2001/XMLSchema#",
			"@vocab": "http://example.com/voc/book/1.0.0/",
			"language":{
				"@type":"@id"
			},
		},
		"@id": "book:38e57c47-3bf5-4320-a94c-de1ad98c5387", //identifier should point to the IRI of the book entity/node to be updated
		"tags":["popular","magic","series","suitable for children"]
	}
}

Response

{
  "id": //identifier , e.g. "open-saber.registry.update",
  "ver": //version "1.0",
  "ets": //epoch timestamp in format "YYYY-MM-DDThh:mm:ssZ+/-nn.nn",
  "params": {
    "resmsgid": "",
    "msgid": "",
    "err": "",
    "status": "successful",
    "errmsg": ""
  },
  "result": {}
}

Case 5

Updating property of an entity by adding a new value to an existing property's list of values for the entity. For example, updating reviews by adding a new review to the list of reviews for the book entity. The operation appends data to an entity. In this case we are adding a new review for the book, so we are targeting the book node.

POST - /create

Request Body


{
	"id": "open-saber.registry.update",
	"ver": "1.0",
	"ets": "11234",
	"params": 
	{
		"did": "",
		"key": "",
		"msgid": ""
	},

	"request": 
	{
		"@context": 
		{
			"rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
			"rdfs": "http://www.w3.org/2000/01/rdf-schema#",
			"book": "http://example.com/voc/book/1.0.0/",
			"xsd": "http://www.w3.org/2001/XMLSchema#",
			"@vocab": "http://example.com/voc/book/1.0.0/",
			"language":{
				"@type":"@id"
			},
		},
		"@id": "book:38e57c47-3bf5-4320-a94c-de1ad98c5387", //identifier should point to the IRI of the book entity/node to be updated
		"reviews":[
		{
			"@type": "Review",
			"reviewComment": "Gripping and fun-filled series.",
			"reviewerName": "Jane Doe"
		}
		]
	}
}

Response

{
  "id": //identifier , e.g. "open-saber.registry.update",
  "ver": //version "1.0",
  "ets": //epoch timestamp in format "YYYY-MM-DDThh:mm:ssZ+/-nn.nn",
  "params": {
    "resmsgid": "",
    "msgid": "",
    "err": "",
    "status": "successful",
    "errmsg": ""
  },
  "result": {}
}

Case 6

Updating property of an entity by adding a new value to an existing property's list of values for the entity. For example, updating genre by adding a new genre to the list of genres for the book entity. The operation appends data to an entity. In this case we are adding a new genre for the book, so we are targeting the book node. So once this entity gets updated, the book entity would have 2 genres, BookTypeCode-FANTASY and BookTypeCode-FICTION

POST - /create

Request Body


{
	"id": "open-saber.registry.update",
	"ver": "1.0",
	"ets": "11234",
	"params": 
	{
		"did": "",
		"key": "",
		"msgid": ""
	},

	"request": 
	{
		"@context": 
		{
			"rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
			"rdfs": "http://www.w3.org/2000/01/rdf-schema#",
			"book": "http://example.com/voc/book/1.0.0/",
			"xsd": "http://www.w3.org/2001/XMLSchema#",
			"@vocab": "http://example.com/voc/book/1.0.0/",
			"genre":{
				"@type":"@id"
			},
		},
		"@id": "book:38e57c47-3bf5-4320-a94c-de1ad98c5387", //identifier should point to the IRI of the book entity/node to be updated
		"genre":["BookTypeCode-FICTION"]
	}
}

Response

{
  "id": //identifier , e.g. "open-saber.registry.update",
  "ver": //version "1.0",
  "ets": //epoch timestamp in format "YYYY-MM-DDThh:mm:ssZ+/-nn.nn",
  "params": {
    "resmsgid": "",
    "msgid": "",
    "err": "",
    "status": "successful",
    "errmsg": ""
  },
  "result": {}
}

Case 7

Updating property of an entity by adding a new value to an existing property's list of values for the entity. For example, updating tags by adding a new tag to the existing list of tags for the book entity. The operation appends data to an entity. In this case we are adding a new tag for the book, so we are targeting the book node. So once this entity gets updated, the book entity would have 5 tags in total, popular,magic,series,suitable for children,fiction

POST - /create

Request Body


{
	"id": "open-saber.registry.update",
	"ver": "1.0",
	"ets": "11234",
	"params": 
	{
		"did": "",
		"key": "",
		"msgid": ""
	},

	"request": 
	{
		"@context": 
		{
			"rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
			"rdfs": "http://www.w3.org/2000/01/rdf-schema#",
			"book": "http://example.com/voc/book/1.0.0/",
			"xsd": "http://www.w3.org/2001/XMLSchema#",
			"@vocab": "http://example.com/voc/book/1.0.0/"
		},
		"@id": "book:38e57c47-3bf5-4320-a94c-de1ad98c5387", //identifier should point to the IRI of the book entity/node to be updated
		"tags":["fiction"]
	}
}

Response

{
  "id": //identifier , e.g. "open-saber.registry.update",
  "ver": //version "1.0",
  "ets": //epoch timestamp in format "YYYY-MM-DDThh:mm:ssZ+/-nn.nn",
  "params": {
    "resmsgid": "",
    "msgid": "",
    "err": "",
    "status": "successful",
    "errmsg": ""
  },
  "result": {}
}

Clone this wiki locally