Contents
See Also
This example demonstrates:
The service forming the basis of this example is the Swagger ‘petstore’ demo. The JSON Swagger service description http://petstore.swagger.io/v2/swagger.json provides the starting point. The petstore API can be viewed and exercised through the Swagger console http://petstore.swagger.io/.
Using the Virtuoso Sponger’s /about service, we can generate an OSDB-compliant RDF service description from the JSON Swagger description of the demo “petstore” service.
http://linkeddata.uriburner.com/about/html/http/petstore.swagger.io/v2/swagger.json?@Lookup@=&refresh=clean
The generated OSDB service description can be viewed using:
http://linkeddata.uriburner.com/about/html/http://linkeddata.uriburner.com/about/id/entity/http/petstore.swagger.io/v2/swagger.json
curl -kX DELETE https://osdb.openlinksw.com/osdb/api/v1/services/swagger_petstore
{"status":"success","method":"unload_service","api":"/osdb/api/v1/services","response":"Unloaded service swagger_petstore from the Service Registry"}
curl -kX POST https://osdb.openlinksw.com/osdb/api/v1/services -d '{"service_description_url":"http://linkeddata.uriburner.com/about/id/entity/http/petstore.swagger.io/v2/swagger.json"}' -H 'Content-Type: application/json'
{"status":"success","method":"load_service","api":"/osdb/api/v1/services","response":"Loaded service description"}
At this point, different aspects of the petstore service can be examined using the OSDB REST API. For instance:
curl -k https://osdb.openlinksw.com/osdb/api/v1/services/swagger_petstore
curl -k https://osdb.openlinksw.com/osdb/api/v1/actions/swagger_petstore
curl -k https://osdb.openlinksw.com/osdb/api/v1/actions/swagger_petstore/finds_pets_by_status
The OSDB UI provides similar views:
The last of the above links displays the OSDB Action Console, which provides a UI for invoking the petstore API. For the remainder of this example, however, we continue with the OSDB REST API.
OSDB calls the petstore API:
DELETE /user/{username} - Delete user
$ curl -ik -X POST -d '{ "username":"kent_c" }' -H 'Content-Type: application/json' https://osdb.openlinksw.com/osdb/api/v1/actions/swagger_petstore/delete_user/exec
HTTP/1.1 200 OK
Content-Type: text/plain; charset=utf-8
Content-Length: 29
...
Success: HTTP status 200 (OK)
OSDB calls the petstore API:
POST /user - Create user
curl -ik -X POST -d '{ "osdb:body_data_src_url":"http://ods-qa.openlinksw.com:8896/DAV/home/nobody/swagger_petstore_create_user_457.json" }' https://osdb.openlinksw.com/osdb/api/v1/actions/swagger_petstore/create_user/exec -H 'Content-Type: application/json'
HTTP/1.1 200 OK
Content-Type: text/plain; charset=utf-8
Content-Length: 29
...
Success: HTTP status 200 (OK)
where swagger_petstore_create_user_457.json contains:
{
"id": 457,
"username": "kent_c",
"firstName": "Clark",
"lastName": "Kent",
"email": "ckent@dailyplanet.com",
"password": "kryptonite",
"phone": "999",
"userStatus": 0
}
OSDB calls the petstore API:
GET /user/{username} - Get user by user name
curl -ik -X POST -d '{ "username":"kent_c", "osdb:response_format": "application/json" }' -H 'Content-Type: application/json' https://osdb.openlinksw.com/osdb/api/v1/actions/swagger_petstore/get_user_by_user_name/exec
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
Content-Length: 153
...
{"id":457,"username":"kent_c","firstName":"Clark","lastName":"Kent","email":"ckent@dailyplanet.com","password":"kryptonite","phone":"999","userStatus":0}
OSDB calls the petstore API:
PUT /user/username - Updated (sic) user
curl -ik -X POST -d '{ "username":"kent_c", "osdb:body_data_src_url":"http://ods-qa.openlinksw.com:8896/DAV/home/nobody/swagger_petstore_update_user_457.json" }' -H 'Content-Type: application/json' https://osdb.openlinksw.com/osdb/api/v1/actions/swagger_petstore/updated_user/exec
HTTP/1.1 200 OK
Content-Type: text/plain; charset=utf-8
Content-Length: 29
...
Success: HTTP status 200 (OK)
where swagger_petstore_update_user_457.json contains:
{
"id": 457,
"username": "kent_c",
"firstName": "Clark",
"lastName": "Kent",
"email": "ckent@dailyplanet.com",
"password": "kryptonite",
"phone": "911",
"userStatus": 0
}
OSDB calls the petstore API:
GET /user/{username} - Get user by user name
curl -ik -X POST -d '{ "username":"kent_c", "osdb:response_format": "application/json" }' -H 'Content-Type: application/json' https://osdb.openlinksw.com/osdb/api/v1/actions/swagger_petstore/get_user_by_user_name/exec
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
Content-Length: 153
{"id":457,"username":"kent_c","firstName":"Clark","lastName":"Kent","email":"ckent@dailyplanet.com","password":"kryptonite","phone":"911","userStatus":0}
OSDB calls the petstore API:
GET /pet/findByStatus - Finds pets by status
(Because ‘petstore’ is a public demo service, the quality of the returned data may be questionable.)
curl -ik -X POST -d '{ "status":"sold" }' -H 'Content-Type: application/json' https://osdb.openlinksw.com/osdb/api/v1/actions/swagger_petstore/finds_pets_by_status/exec
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
Content-Length: 309147
[{"id":4097347280,"category":{"id":1501926581,"name":"dog"},"name":"hello kity","photoUrls":["http://foo.bar.com/1","http://foo.bar.com/2"],"tags":[{"id":681689363,"name":"swagger-codegen-python-pet-tag"}],"status":"sold"}, ...