Package APIs with Dev Portal

Incompatible with
on-prem
Minimum Version
Kong Gateway - 3.13
TL;DR

Packaging APIs involves the following steps:

  1. Create an API and attach an OpenAPI spec.
  2. Apply the Access Control Enforcement (ACE) plugin globally on the control plane you want to link.
  3. Link a control plane to the API to allow developer consumption.
  4. Create an API package by adding operations and package rate limits.
  5. Publish the API package to Dev Portal.

Prerequisites

This is a Konnect tutorial and requires a Konnect personal access token.

  1. Create a new personal access token by opening the Konnect PAT page and selecting Generate Token.

  2. Export your token to an environment variable:

     export KONNECT_TOKEN='YOUR_KONNECT_PAT'
    
  3. Run the quickstart script to automatically provision a Control Plane and Data Plane, and configure your environment:

     curl -Ls https://get.konghq.com/quickstart | bash -s -- -k $KONNECT_TOKEN --deck-output
    

    This sets up a Konnect Control Plane named quickstart, provisions a local Data Plane, and prints out the following environment variable exports:

     export DECK_KONNECT_TOKEN=$KONNECT_TOKEN
     export DECK_KONNECT_CONTROL_PLANE_NAME=quickstart
     export KONNECT_CONTROL_PLANE_URL=https://us.api.konghq.com
     export KONNECT_PROXY_URL='http://localhost:8000'
    

    Copy and paste these into your terminal to configure your session.

decK is a CLI tool for managing Kong Gateway declaratively with state files. To complete this tutorial, install decK version 1.43 or later.

This guide uses deck gateway apply, which directly applies entity configuration to your Gateway instance. We recommend upgrading your decK installation to take advantage of this tool.

You can check your current decK version with deck version.

To recover create API packages, you need the following roles:

  • Editor role for APIs
  • Publisher role for the API and API package
  • API Creator

For this tutorial, you’ll need a Dev Portal pre-configured. If you don’t have these settings already configured, follow these steps to pre-configure it:

  1. In the Konnect sidebar, click Dev Portal.
  2. Click New portal.
  3. Enter a name for your Dev Portal.
  4. Click Create and continue.
  5. Customize your Dev Portal’s appearance.
  6. Click Save.

To complete this guide, you’ll need an API in Catalog:

  1. In the Konnect sidebar, click Catalog.
  2. Click New API.
  3. In the API name field, enter MyAPI.
  4. Click Create.

For this tutorial, you’ll need Kong Gateway entities, like Gateway Services and Routes, pre-configured. These entities are essential for Kong Gateway to function but installing them isn’t the focus of this guide.

  1. Run the following command:

    echo '
    _format_version: "3.0"
    services:
      - name: example-service
        url: http://httpbin.konghq.com/anything
    routes:
      - name: example-route
        paths:
        - "/anything"
        methods:
        - GET
        - PUT
        - POST
        - PATCH
        - DELETE
        service:
          name: example-service
    ' | deck gateway apply -
    

    To learn more about entities, you can read our entities documentation.

To complete this guide, you’ll need an API specification that matches the Route you created. Catalog uses the spec to add operations to your API package.

cat > example-api-spec.yaml << 'EOF'
openapi: 3.0.0
info:
  title: Example API
  description: Example API service for testing and documentation
  version: 1.0.0

servers:
  - url: http://httpbin.konghq.com
    description: Backend service (HTTP only, port 80)

paths:
  /anything:
    get:
      summary: Get anything
      description: Echo back GET request details
      operationId: getAnything
      tags:
        - Echo
      responses:
        '200':
          description: Successful response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/EchoResponse'
        '426':
          description: Upgrade Required (HTTPS redirect)
          
    post:
      summary: Post anything
      description: Echo back POST request details
      operationId: postAnything
      tags:
        - Echo
      requestBody:
        content:
          application/json:
            schema:
              type: object
              additionalProperties: true
      responses:
        '200':
          description: Successful response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/EchoResponse'
        '426':
          description: Upgrade Required (HTTPS redirect)
                
    put:
      summary: Put anything
      description: Echo back PUT request details
      operationId: putAnything
      tags:
        - Echo
      requestBody:
        content:
          application/json:
            schema:
              type: object
              additionalProperties: true
      responses:
        '200':
          description: Successful response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/EchoResponse'
        '426':
          description: Upgrade Required (HTTPS redirect)
                
    patch:
      summary: Patch anything
      description: Echo back PATCH request details
      operationId: patchAnything
      tags:
        - Echo
      requestBody:
        content:
          application/json:
            schema:
              type: object
              additionalProperties: true
      responses:
        '200':
          description: Successful response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/EchoResponse'
        '426':
          description: Upgrade Required (HTTPS redirect)
                
    delete:
      summary: Delete anything
      description: Echo back DELETE request details
      operationId: deleteAnything
      tags:
        - Echo
      responses:
        '200':
          description: Successful response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/EchoResponse'
        '426':
          description: Upgrade Required (HTTPS redirect)

components:
  schemas:
    EchoResponse:
      type: object
      properties:
        args:
          type: object
          description: Query parameters
        data:
          type: string
          description: Request body data
        files:
          type: object
          description: Uploaded files
        form:
          type: object
          description: Form data
        headers:
          type: object
          description: Request headers
        json:
          type: object
          description: JSON request body
        method:
          type: string
          description: HTTP method used
        origin:
          type: string
          description: Origin IP address
        url:
          type: string
          description: Request URL

x-kong-service:
  name: example-service
  host: httpbin.konghq.com
  port: 80
  protocol: http
  path: /anything
  retries: 5
  connect_timeout: 60000
  write_timeout: 60000
  read_timeout: 60000

x-kong-route:
  name: example-route
  protocols: [http, https]
  methods: [GET, POST, PUT, PATCH, DELETE]
  paths: [/anything]
  strip_path: true
  preserve_host: false
  https_redirect_status_code: 426
EOF

You can compose API packages from existing APIs in Dev Portal. API packages allow you to:

  • Create distinct APIs for specific use cases or partners based on existing API operations.
  • Link to multiple Gateway Services and/or Routes for developer self-service and application registration.
  • Apply rate limiting policies to an API Package, or per operation.
  • Manage role-based access control for specific developers and teams.

Associate a control plane

To allow developers to consume your API, you must first link an API Gateway and control plane to your API.

Operations from your API’s OpenAPI spec should overlap with Routes to ensure requests will be routed to the correct Service. Gateway routing configuration isn’t directly modified by adding operations.

  1. In the Konnect sidebar, click Catalog.
  2. Click MyAPI.
  3. Click the Gateway tab.
  4. Click Link gateway.
  5. From the Control plane dropdown menu, select “quickstart”.
  6. Select Link to a control plane.
  7. In the Add the Access Control and Enforcement plugin settings, click Add plugin.
  8. Click Link gateway.
  9. Click the API Specification tab.
  10. Click Upload Spec.
  11. Click Select file.
  12. Select example-api-spec.yaml.
  13. Click Save.

Assign operations to API packages

Now, you can create an API package by picking operations from your API. Operations are automatically mapped to Routes using your API’s OpenAPI spec. The Gateway configuration isn’t directly modified – any unmatched operations will be highlighted to indicate that a user needs Gateway Manager permissions to perform an action.

  1. In the Konnect sidebar, click Catalog.
  2. Click the API packages tab.
  3. Click Create API package.
  4. In the API package name field, enter Company package.
  5. Enable the Package rate limit.
  6. For the rate limit, enter 5 and select “Minute”.
  7. In the API operations settings, click Add operations from APIs.
  8. In the Add API operations pane, click MyAPI
  9. For GET /anything, click Add.
  10. For PUT /anything, click Add.
  11. For POST /anything, click Add.
  12. Exit the Add API operations pane.
  13. Click Create API package.
  14. Click the Specifications tab.
  15. Click Generate spec from operations.
  16. Click Save.

Publish API packages to Dev Portal

Now you can make the API packages available to developers by publishing them to a Dev Portal.

  1. In the Konnect sidebar, click Catalog.
  2. Click the API packages tab.
  3. Click Company package.
  4. Click Publish API.
  5. From the Portal dropdown menu, select your Dev Portal.
  6. From the Authentication strategy dropdown menu, select “Disabled”.
  7. Click Public.
  8. Click Publish API.

Your API package will now be published to your Dev Portal. Published API packages appear the same as published APIs in the Dev Portal, and both allow developers to register applications with them.

Validate

Now that you’ve published your API package, you can verify that it was successfully published by navigating to your Dev Portal’s URL. You can find your Dev Portal’s URL by navigating to the Dev Portal overview in the Konnect UI.

Cleanup

If you created a new control plane and want to conserve your free trial credits or avoid unnecessary charges, delete the new control plane used in this tutorial.

Something wrong?

Help us make these docs great!

Kong Developer docs are open source. If you find these useful and want to make them better, contribute today!