Contact Free trial Login

Create an API Using a CRD

After you provision the adapter, you must create an API to bind to the service. You can create an API using Anypoint Platform or Anypoint Service Mesh:

  • Create an API using Anypoint Platform

    If you want to create REST or SOAP APIs with OAS or WSDL definition, use Anypoint Platform.

    Note that if you want to upload a REST API or OAS asset type, use a .json or .yaml file. Alternatively, if you want to upload a SOAP API or WSDL asset type, use a .wsdl or .xml file.

  • Create an API using Anypoint Service Mesh Autocreate

    Anypoint Service Mesh enables you to automatically create an HTTP API in Anypoint Platform, with no REST or SOAP definitions. You do not have to manually log in to Anypoint Platform.

    If you automatically create REST or SOAP APIs with Anypoint Service Mesh, the APIs are still managed internally as an HTTP asset without any definition.

Create an API Using Anypoint Platform

To create an API using Anypoint Platform, perform the following steps:

  1. Go to Anypoint Platform > API Manager and select the Manage API drop-down list.

  2. Select Create new API.

    The Creating an asset page is displayed.

  3. Specify the Name, and Asset types details for the API.

    Your Asset is now created in Exchange for reuse. After you create the Asset, you are now ready to perform Endpoint configuration.

    The Endpoint Configuration window is displayed.

  4. In the Managing type field, select the Basic Endpoint radio button.

  5. In the Application type field, select the Non-Mule application radio button.

  6. Optionally, specify the Implementation URI, and click Save.

    Your API is now created.

Create an API Using Anypoint Service Mesh

Use the procedure in this section to automatically create an API using Anypoint Service Mesh. Before you create the API, you must complete the task prerequisite.

Task Prerequisites

Before you begin, ensure that you obtain the:

  • Environment ID and organization ID.

    To obtain these details, go to API Manager > Environment Information.

  • Manage APIs Configuration permission for the environment where you are creating the API Instance.

  • Exchange Contributor permission for the business group where you are creating the asset.

To create an API in Anypoint Platform using Anypoint Service Mesh:

  1. Create your api definition file and save it with a '.yaml' file extension, for example test-api.yaml:

    apiVersion: servicecatalog.k8s.io/v1beta1
    kind: ServiceInstance
    metadata:
      name: _Kubernetes API resource name_ # example: orders-api
      namespace: _namespace name_ # example: default
      labels:
        service-mesh.mulesoft.com/kind: api
    spec:
      clusterServiceClassExternalName: anypoint-platform-api-instance
      clusterServicePlanExternalName: service-mesh
      parameters:
        environmentId: _environment ID_ # example: 7cea45c6-3237-464d-bd34-3122c4abde29
        groupId: _group ID_ # Optional - example: 350b8164-e809-4091-91f5-079fb30e5a1e
        assetId: _asset ID_ # example: orders-api
        version: _version_ # example: 0.0.1
        instanceLabel: _instance label_ # example: public
        tags:
          apiSpec:
          - _tag in Exchange asset_ # example: orders
          apiInstance:
          - _tag in API Manager instance_ # example: orders
        user: _Username of the Anypoint Platform user_
        password: _Password of the Anypoint Platform user_
  2. Apply the CRD file using the following command: kubectl apply -f test-api.yaml

  3. Verify the API status using the following command: asmctl api list

    The API that was created is displayed.

  4. Optionally, you can verify that an asset is created on Exchange and an API is created on API Manager.

Reference Kubernetes Secret

Anypoint Service Mesh supports the use of Kubernetes secrets to store and manage sensitive information, such as your user credentials.

Task Prerequisites

You must have the required permissions to create the Kubernetes secret.

To store your user credentials in Kubernetes secrets:

  1. In a YAML file, create a secret in which to store the sensitive information, for example, orders-api-config.yaml:

    apiVersion: v1
    kind: Secret
    metadata:
      name: _secret name_ # example: orders-api-config
      namespace: _namespace name_ # example: default
    type: Opaque
    stringData:
      config: |
        {
          "user": "_replace-with-anypoint-username_",
          "password": "_replace-with-anypoint-clientSecret_"
        }
  2. Apply the secret:

    kubectl apply -f orders-api-config.yaml

    If the secret is correctly applied, a 'secret/orders-api-config created' message is displayed.

  3. Reference the secret in your API CRD (instead of the user and password parameter), as illustrated in the following example:

    apiVersion: servicecatalog.k8s.io/v1beta1
    kind: ServiceInstance
    metadata:
      name: _Kubernetes API resource name_ # example: orders-api
      namespace: _namespace name_ # example: default
      labels:
        service-mesh.mulesoft.com/kind: api
    spec:
      clusterServiceClassExternalName: anypoint-platform-api-instance
      clusterServicePlanExternalName: service-mesh
      parameters:
        environmentId: _environment ID_ # example: 7cea45c6-3237-464d-bd34-3122c4abde29
        groupId: _group ID_ # Optional - example: 350b8164-e809-4091-91f5-079fb30e5a1e
        assetId: _asset ID_ # example: orders-api
        version: _version_ # example: 0.0.1
        instanceLabel: _instance label_ # example: public
        tags:
          apiSpec:
          - _tag in Exchange asset_ # example: orders
          apiInstance:
          - _tag in API Manager instance_ # example: orders
      parametersFrom: # The element specifies the secret name and configuration required for retrieving the parameters.
        - secretKeyRef:
            name: _secret name_ # example: orders-api-config
            key: config

Was this article helpful?

💙 Thanks for your feedback!

Edit on GitHub