Unknown macro: {next_previous_links}
Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 6 Next »

Follow the instructions given below to generate a REST API using a Swagger definition. Alternatively, you can create a REST API using WSO2 Integration Studio.

Note that this feature is currently available through the management console of the ESB profile.

Prerequisites

The Swagger UI requires to have CORS configured in order to function properly. The following steps should be followed to correctly configure CORS.

Open the <EI_HOME>/conf/synapse.propertiesfile and add the following configuration.

synapse.rest.CORSConfig.enabled=true
synapse.rest.CORSConfig.Access-Control-Allow-Origin=https://localhost:9443​,http://localhost:8280
synapse.rest.CORSConfig.Access-Control-Allow-Headers=content-type

Notice the synapse.rest.CORSConfig.Access-Control-Allow-Origin property has a value of https://localhost:9443 and this will enable CORS for localhost. You can define as many URLs as desired as comma-separated values so that CORS will be enabled for all defined URLs.

Step 1: Generating the API

  1. Open the management console of the WSO2 Enterprise Integrator and click on APIsin the Maintab. Click on Generate APIas depicted in the image below.


    The Swagger UI will then open. On the left side, the Swagger definition of a sample API is shown and on the right side, the details of the API is shown. You can edit the Swagger definition as desired or import your own Swagger definitions by importing via a URL or uploading a definition file through the File menu of the Swagger editor.

  2. Once done, click on the Generate API button to generate the API as depicted below.

    The synapse configuration of the generated API will then be shown.
  3. Clicking Save will save the API and redirect to the Deployed APIssection.

     
    • 1 - The swaggerbutton will direct to the swagger definition of the API
    • 2 - The Try This APIbutton will direct to the TryIt tool which allows testing the API

Step 2: Editing the API (Optional)

  1. Click the Edit button and it will open the Edit API view. Click on the Edit swagger button to view the Swagger editor.

    On the left side, the editable swagger definition is shown and on the right side, API details along with the Try it out options are shown. More details about the Try it out tool is explained in the next sections of this guide.
  2. Once done with the editing, click on the Apply Changes button and it will redirect to the Edit API view. Click Save in the Edit API view and the API will be saved and you will be redirected back to the Deployed APIsview.

Step 3: Trying out the API

  1. In the Deployed APIs view, click on the Try This API to try out the API with sample requests and responses. Clicking this will open the Try out tool in a new browser tab. Note that this UI is accessible even without logging in to the WSO2 EI.

  2. In the ​Try it out view, defined services of the API are shown and once you click on a service, it will expand and show the evaluate view of the selected service.

  3. Click on the Try it outbutton and it will show the following view.

  4. You can edit the payload and also set the content type of the request and the response. Click on Executeto send the request.

The response will be shown along with several other details such as the cURL command used, request URL, response code and etc.

  • No labels