This documentation is a work in progress and will be released with the WSO2 API Manager 4.0.0 GA release.
M30_Microgateway Quick Start - API Manager 4.0.0 - WSO2 Documentation

All docs This doc
Skip to end of metadata
Go to start of metadata
 What is the API Microgateway?

The API Manager Microgateway is a specialized form of the WSO2 API Gateway. Its main characteristics are:

  • The ability to execute in isolation without mandatory connections to other components (Key Manager, Traffic Manager, etc).
  • The ability to host only a subset of specific APIs (defined in the API Publisher), instead of all.
  • Immutability; if you update an API, you need to re-create the container/instance and hot deployment is not possible.

Microgateway offers you a proxy that is capable of performing security validations (OAuth, Signed JWT), in-memory (local) rate limiting and operational analytics.

Before you begin,

  1. Download the Microgateway distribution and extract it.
  2. Optionally, Identify the path to the bin folder of the extracted Microgateway. To avoid typing the whole path to the /bin folder of the microgateway each time the microgateway needs to be started, on the CLI,  add the /bin folder path  as a PATH environment variable.

If you are unable to append the path, you can alternatively run the Microgateway commands by navigating to the <MICROGW_HOME>/bin folder and running the commands as ./micro-gw instead.

Let's go through the main use case of the Microgateway:

Deploy and subscribe to the sample API 

  1. Open the API Publisher (https://<hostname>:9443/publisher) and sign in with admin/admin credentials.

  2. Click the Deploy Sample API button. It deploys a sample API called PizzaShackAPI into the API Manager.

    The Deploy Sample API option is available only when there are no APIs in API Publisher. If you have already created a API, this option is not available.

  3. Click PizzaShackAPI to open it. 
  4. Go to the Lifecycle tab and note that the State is PUBLISHED. The API is already published to the API Store.
  5. Sign in to the API Store (https://<hostname>:9443/store) with the admin/admin credentials and click the PizzaShackAPI API.
  6. Expand the API Credentials section.
  7. Select the Express Mode.
  8. Give an application name and click Next to go to step 2.
  9. At Step 2, Click Next again and go to step 3.
  10. Click Next at step 3 to go to step 4. 
  11. On step 5, copy the access token created and click Finish.
  12. Click on the Overview tab and expand the API Credentials sections to view the subscriptions.

Generate a distribution for a single API

It is possible to create a Microgateway distribution for a single API that is in the Published state. 

For details on how to create a Microgateway distribution for a group of APIs, see Grouping APIs with Labels.

  1. Navigate to a preferred workspace folder using the command line.
    This location is used to run the Microgateway commands and to generate Microgateway artifacts.
  2. Set up a project using the command given below,

    micro-gw setup <project_name> -a <API_name> -v <version>

    When the tool requests for the username and password, use admin in both instances. Use the default values for the other parameters by pressing Enter

    Here is an example:

    $ micro-gw setup pizzashack-project -a PizzaShackAPI -v 1.0.0
    Enter Username: 
    Enter Password for admin: 
    Enter APIM base URL [https://localhost:9443/]: 
    Enter Trust store location: [lib/platform/bre/security/ballerinaTruststore.p12]
    Enter Trust store password: [ use default? ]
    Setting up project pizzashack-project is successful.

    When the above command is issued, the tool connects with API Manager REST APIs and retrieves the API specified above. The source artifacts are generated in the current folder location.

    The folder structure looks similar to the following,

    └── pizzashack-project
        ├── conf
        │   └── deployment-config.toml
        ├── src
        │   ├── extension_filter.bal
        │   ├── listeners.bal
        │   ├── PizzaShackAPI_1_0_0.bal
        │   └── policies
        │       ├── application_10PerMin.bal
        │       ├── application_20PerMin.bal
        │       ├── ...
        │       ├── subscription_Bronze.bal
        │       ├── subscription_Gold.bal
        │       ├── ...
        │       ├── subscription_Unauthenticated.bal
        │       └── throttle_policy_initializer.bal
        └── target

    If you re-run the setup command while you already have a project named pizzashack-project in the current working directory, you receive an error similar to the following:

    $ micro-gw setup pizzashack-project -a PizzaShackAPI -v 1.0.0
    [micro-gw: Project name `pizzashack-project` already exist. use -f or --force to forcefully update the project directory., Run 'micro-gw help' for usage.]

    As suggested in the above output, if you need to override the current project, run the setup command with the -f (--force)option.

    $ micro-gw setup pizzashack-project -a PizzaShackAPI -v 1.0.0  -f
    Enter Password for admin: 
    Setting up project pizzashack-project is successful.
  3. Build the microgateway distribution for the project using the following command:

    micro-gw build <project_name>

    Here is an example:

    $ micro-gw build pizzashack-project
    Build successful for the project - pizzashack-project

    Once the above command is executed, the generated source files are built and a Microgateway distribution is created in the target folder. 

    The name of the distribution will have the format micro-gw-<project_name>.zip. In the above example, the name will be micro-gw-pizzashack

  4. Next, unzip the and run the gateway shell script inside the bin folder of the extracted zip using the following command:

    bash gateway

    The Microgateway will now start for the Pizzashack API. For example,

    micro-gw-pizzashack-project/bin$ bash gateway
    ballerina: HTTP access log enabled
    ballerina: initiating service(s) in '/home/user/workspace/pizzashack-project/target/micro-gw-pizzashack-project/exec/pizzashack-project.balx'
    ballerina: started HTTPS/WSS endpoint
    ballerina: started HTTPS/WSS endpoint
    ballerina: started HTTP/WS endpoint

You have successfully generated and started a Microgateway distribution for the Pizzashack API. 

  • No labels