Software Development Kits (SDKs) contain the necessary toolkits to create an application using the OS to call the local API. If an API consumer wants to create an application, they can generate a server stub or client side SDK for a supported language/framework and use it to write a software application to consume the subscribed APIs.
Generating client SDKs in the API Store
By default, SDK generation is enabled for Java and Android. If those two languages are sufficient, move to step 3. To enable SDK generation for other languages,
Open the
<APIM_Home>/repository/conf/api-mamanger.xml
file and edit the<SupportedLanguages>
property of the<SwaggerCodegen>
element to include any of the supported languages/frameworks. An example is shown below,<SwaggerCodegen> <ClientGeneration> <GroupId>org.wso2</GroupId> <ArtifactId>org.wso2.client.</ArtifactId> <ModelPackage>org.wso2.client.model.</ModelPackage> <ApiPackage>org.wso2.client.api.</ApiPackage> <!-- Configure supported languages/Frameworks as comma separated values, Supported Languages/Frameworks : android, java, scala, csharp, cpp, dart, flash, go, groovy, javascript, jmeter, nodejs, perl, php, python, ruby, swift, clojure, aspNet5, asyncScala, spring, csharpDotNet2, haskell--> <SupportedLanguages>java,android,ruby,php</SupportedLanguages> </ClientGeneration> </SwaggerCodegen>
In this example, the supported languages are defined as Java, Android, Ruby and PHP.- Once the above configuration is saved, start the API Manager server.
- In the API Store, open the API and click the SDKs tab. Download options are available for each programming language specified earlier in the
api-manager.xml
file. Download the SDK for the preferred language and use it to write software applications to consume the API.
Tip: As mentioned above, a valid subscription should exist for the API. The SDK cannot be used without a valid access token for the subscription.
Generating server stubs and client SDKs in the API Publisher
The API Publisher has an embedded swagger editor with the ability to generate server code and client SDKs then and there.
- Open an existing API and choose to edit it.
- Click Edit Source to open the embedded swagger editor.
- To generate and download a server stub, click Generate Server and select a server stub from the list.
- To generate and download a client SDK, click Generate Client and select a client from the list.
The generated server stubs and client SDKs are generated using Swagger Codegen.
It is recommended to add the securityDefinitions
in the swagger definition to be able to pass access tokens when invoking an API. Edit the source of the API from the API Publisher and add the code given below.
securityDefinitions: default: type: oauth2 authorizationUrl: 'https://<GW-HOST>:<GW-POST>/authorize' flow: implicit scopes: {} security: - default: []