Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  1. Log in to the API Publisher and choose to design a new API.
    Image RemovedImage Added
  2. In the Design tab, give an API name, a context and a version, and click the Edit Source button under the API Definition section.
    Image RemovedImage Added
  3. The Swagger UI opens. Add the following code under the paths object and click Save. It adds a resource with two HTTP methods into the API.

    Tip

    Tip:

    In the below code, note that you have a resource defined with the URL pattern /CheckPhoneNumber under the paths object. This is followed by the HTTP methods GET and POST. For each HTTP method, the following parameters are defined.

    • x-auth-type: WSO2-specific object to define the authentication type of the method.
    • x-throttling-tier: WSO2-specific object to define the throttling tier of the method.
    • responses: An object to hold responses that can be used across operations. See the Swagger specification for details.
    Code Block
    /CheckPhoneNumber:
        get:
          x-auth-type: "Application & Application User"
          x-throttling-tier: Unlimited
          responses:
            "200": {}
        post:
          x-auth-type: "Application & Application User"
          x-throttling-tier: Unlimited
          responses:
            "200": {}    


  4. Back in the API Publisher, note that a resource with two HTTP methods are added to the API.
    Let's say the backend of this API sends the response in XML format. Let's document this under the GET method in the resource that we just added. 
  5. Add the following code under the GET method and click Save.

    Code Block
    produces: [text/xml]

  6. Back in the API Publisher, expand the GET method and note that the response content type has changed to XML. 

    Tip

    Tip: You can use this attribute to document the type of the response message that the backend sends. It doesn't do any message type conversion. You can add multiple values as a comma-separated list. E.g., produces: "[text/xml], [application/json]"

  7. Add the following code under the GET method and click Save. It adds two parameters to the method.

    Code Block
    parameters:
            - description: Give the phone number to be validated
              name: PhoneNumber
              type: string
              required: true
              in: query
            - description: Give the license key as 0 for testing purpose
              name: LicenseKey
              type: string
              required: true
              in: query

  8. Back in the API Publisher, note the two parameters with their descriptions that are added under the GET method.
  9. In the Swagger UI, add the following summary and description to the GET method and click Save.

    Code Block
    summary: Check the validity of your phone number
    description: "Phone Verification validates a telephone number and returns carrier information, location routing etc."

  10. Back in the API Publisher, note the summary and description appearing under the GET method.
  11. In the Swagger UI, add the following code under the POST method and click Save. It adds two parameters as PhoneNumber and LicenseKey to pass the payload in. It also changes the datatypes of the parameters to application/x-www-form-urlencoded as the backend expects that datatype.

    Code Block
    parameters:
            - description: Give the phone number to be validated
              name: PhoneNumber
              required: true
              type: string
              in: formData
            - description: Give the license key as 0 for testing purpose
              name: LicenseKey
              required: true
              type: string
              in: formData
    consumes: 
            - application/x-www-form-urlencoded

  12. Back in the API Publisher, note the parameters that you added are visible under the POST method.

  13. In the Swagger API, change the title of the API as follows. This is the title that is visible to the consumers in the API Console of the API Store, after the API is published.

    Code Block
    info:
      title: PhoneVerificationAPI


    You will see how this change is reflected in the API Store in the last step of this tutorial.

  14. Complete the rest of the API creation process. Once you are done, click Save and Publish on the Manage tab to publish the API to the API Store.
  15. Log in to the API Store and click on the API that you just published.
  16. The API opens. Go to its API Console tab and note the changes that you did earlier now appearing in the API Store for consumers.

...