Wednesday, March 12, 2014

Governance Registry is enriched with REST API capabilities

Now Governance Registry is enriched with REST API capabilities that can perform CRUD operations via HTTP protocol on the registry resources. These operations are secured with OAuth 2.0. CRUD operations can be performed to following registry properties.
  • Collection - Add / Delete / Get collections
  • Resources - Add / Get / Update / Delete resources 
  • Comments - Add / Read / Update / Delete comments
  • Properties - Add / Read / Update / Delete properties
  • Tags - Add / Read / Update / Delete tags
  • Associations - Add / Read / Update / Delete associations
  • Rating - - Add / Read / Update / Delete ratings
To do this first login to the API Store and subscribe to the "API - 1.0.0" api. Then generate the access token. Else you can use the Base64 encoding of Consumer key and Consumer secret to invoke REST API. Following are the curl commands to REST API invocations or else you can use the Advance Rest Client in the browser to invoke REST API.

Collection
Add
curl -v -X PUT "http://localhost:9763/resource/1.0.0/artifact/_system/governance/TestCollection" -H "Authorization: Bearer 7754c5f4e847dc3a5e9f9d26aeccac8" -H "Content-Type: application/atomcoll+xml"

Get
curl -v -X GET "http://localhost:9763/resource/1.0.0/artifact/_system/governance/" -H "Authorization: Bearer 7754c5f4e847dc3a5e9f9d26aeccac8"

Delete
curl -v -X DELETE "http://localhost:9763/resource/1.0.0/artifact/_system/governance/TestCollection" -H "Authorization: Bearer 7754c5f4e847dc3a5e9f9d26aeccac8" -H "Content-Type: application/atomcoll+xml"

Resources
Add
curl -v -X PUT -d @addResource.txt "http://localhost:9763/resource/1.0.0/artifact/_system/governance/addResource.txt" -H "Authorization: Bearer 7754c5f4e847dc3a5e9f9d26aeccac8" -H "Content-Type:text/plain"

Get
curl -v -X GET "http://localhost:9763/resource/1.0.0/artifact/_system/governance/addResource.txt" -H "Authorization: Bearer 7754c5f4e847dc3a5e9f9d26aeccac8"

Update
curl -v -X POST -d @updateResource.txt "http://localhost:9763/resource/1.0.0/artifact/_system/governance/updateResource.txt" -H "Authorization: Bearer 7754c5f4e847dc3a5e9f9d26aeccac8" -H "Content-Type: text/plain"

Delete
curl -v -X DELETE "http://localhost:9763/resource/1.0.0/artifact/_system/governance/addResource.txt" -H "Authorization: Bearer 7754c5f4e847dc3a5e9f9d26aeccac8" -H "Content-Type: text/plain"

Likewise you can do all CRUD operations to the above mentioned registry properties. More details can be get from WSO2 Greg site.


1 comment:

  1. Hi Aparna:

    I am evaluating WSO2 GREG 4.6. and very interested in using the REST API. After I read all the docs available on the WSO2 site, I decided to give a try following the instructions first. I got the token (not expired). then I tried to give a url like:
    http://localhost:9763/restapi/comments?path=/_system the request got denied with status 200. the Reponse was really the log in screen. No matter what URLs I tried: with your url listed above (I didn't use curl), urls found on the site, change the path value... However, none worked. The response was always the html log in screen. Please advise. For what it is worth, this is what I tried with the Collection Get example above:

    C:\temp>curl -v -X GET "http://localhost:9763/resource/1.0.0/artifact/_system/governance/" -H "Authorization: Bearer 1446ad2dccd077bdc189c871d6bc778"
    * Adding handle: conn: 0x57ac50
    * Adding handle: send: 0
    * Adding handle: recv: 0
    * Curl_addHandleToPipeline: length: 1
    * - Conn 0 (0x57ac50) send_pipe: 1, recv_pipe: 0
    * About to connect() to localhost port 9763 (#0)
    * Trying 127.0.0.1...
    * Connected to localhost (127.0.0.1) port 9763 (#0)
    > GET /resource/1.0.0/artifact/_system/governance/ HTTP/1.1
    > User-Agent: curl/7.33.0
    > Host: localhost:9763
    > Accept: */*
    > Authorization: Bearer 1446ad2dccd077bdc189c871d6bc778
    >
    < HTTP/1.1 403 Forbidden
    < Content-Type: application/xml;charset=UTF-8
    < Content-Length: 270
    < Date: Wed, 04 Jun 2014 19:35:48 GMT
    * Server WSO2 Carbon Server is not blacklisted
    < Server: WSO2 Carbon Server
    <
    900901Invalid CredentialsA
    ccess failure for API: /resource, version: 1.0.0 with key: 1446ad2dccd077bdc189c871d6bc778* Connection #0 to host localh
    ost left intact

    Thank you


    ---Yang

    ReplyDelete