Generating SDKs
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. Â
Client SDK and Server Stub generation in API Publisher is only supported for Rest APIs.
- 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.
API deveopers can use the Generate Server option to generate the REST API structure based on the swagger definition. The actual backend implementation can be developed on top of the code generated using swagger code generator. You can select from a list of frameworks to generate the actual backend implementation stub of the REST API. - 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-PORT>/authorize' flow: implicit scopes: {} security: - default: []