Social Icons

twitterfacebookgoogle pluslinkedinrss feedemail

Pages

Friday, November 29, 2013

PHP library for calling WSO2 API manager publisher

My need is to create an application that manages the creation of API from a single central point (a PHP site).

The WSO2 API manager has some interesting REST API that can be used to create programmatically an API.

To manage these API better I've developed (still in development) a library that calls the API manager, manage errors and wrap the whole up.

If you need it here is the link to github.

The usage of the library is pretty straightforward:

You create the class passing the address of the API manager (and optionally the user and password, it default to the default admin/admin)

$wso2api = new Wso2API("http://10.118.8.73:9763");

Than create the two array with the parameters to pass for the creation:

$create_api_post = array('name'=>'WikipediaAPI',
                         'visibility'=>'public',
                         'version'=>'1.0.0',
                         'description'=>'If you want to monitor a MediaWiki installation',
                         'endpointType'=>'nonsecured',
                         'http'=>true,
                         'https'=>false,
                         'endpoint'=>'http://en.wikipedia.org/w/api.php',
                         'wsdl'=>'',
                         'wadl'=>'',
                         'tags'=>'wikipedia,mediawiki',
                         'tier'=>'Silver',
                         'thumbUrl'=>'https://upload.wikimedia.org/wikipedia/en/b/bc/Wiki.png',
                         'bizOwner'=>'Luca Gioppo',
                         'provider'=>'admin',
                         'context'=>'/wikipedia',
                         'tiersCollection'=>'Gold',
                        );

$create_api_resources = array (array('resourceMethod'=>'GET',
                                     'resourceMethodAuthType'=>'Application',
                                     'resourceMethodThrottlingTier'=>'Unlimited',
                                     'uriTemplate'=>'/*'));

In the end you can just call the create method that can accept also the autopublish flag that manage the settings of the API in PUBLISHED state in one call (usually API are in CREATED state and you have to set it to PUBLISH as a second step.

$ret = $wso2api->create_api($create_api_post, $create_api_resources, $autopublish = true);

0 commenti: