Skip to content

Developer Portal

Create a fully customizable self-serve API catalog for easy API discovery. Empower developers to browse, discover, test, and register for your APIs.

  1. Ingresar al menú llamado Dev Portal.
  2. En el submenú llamado Portals, dar click en el botón + Create a new portal
  3. Elejir la opción de visibilidad como Public portal
  4. Colocarle de nombre MyDevPortal y dar click en el botón Create and continue
  5. A continuación, dar click en el botón Save
  6. Luego dar click en el botón Go to overview
  7. Debes copiar y guardar en un lugar seguro el ID y URL del nuevo Developer Portal
  8. Puedes crear un archivo de variables, llamarlo env.sh con el siguiente contenido de ejemplo en el servidor Docker:
    #!/bin/bash
    # Generales
    export OPENAI_API_KEY=sk-proj-3jX8YvkmhIFQA
    export KONNECT_CONTROL_PLANE_URL=https://us.api.konghq.com
    export CONTROL_PLANE_ID=f38-231-40d-8a9-063dea
    export KONNECT_TOKEN=kpat_s1YjaZgs27E
    export DECK_KONNECT_CONTROL_PLANE_NAME=workshop-itm
    export DECK_OPENAI_API_KEY=$OPENAI_API_KEY
    export DECK_KONNECT_TOKEN=$KONNECT_TOKEN
    export DECK_REDIS_HOST=redis
    # Gateway Proxy
    export KONG_GATEWAY_SERVER=student-0-aio.34-82-238-123.nip.io
    # Dev Portal
    export PORTAL_ID='f9bb-50f-4e8-876-4d2fb'
    export PORTAL_URL='39a47.us.kongportals.com'
    
  9. Cargar la variables de entorno con el siguiente comando:
    source env.sh
    
  10. Crear un servicio y una ruta para utilizar en este laboratorio, ejecutar el siguiente comando en el servidor Docker:
    echo '
    _format_version: "3.0"
    services:
      - name: dev_portal_example-service
        url: http://httpbin.konghq.com/anything
    routes:
      - name: dev_portal_example-route
        paths:
        - "/anything-demo"
        service:
          name: dev_portal_example-service
    ' | deck gateway apply -
    
  11. Crear una nueva página dentro del Developer Portal, ejecutar el siguiente comando en el servidor Docker:
    curl -X POST "$KONNECT_CONTROL_PLANE_URL/v3/portals/$PORTAL_ID/pages" \
         -H "Accept: application/json"\
         -H "Content-Type: application/json"\
         -H "Authorization: Bearer $DECK_KONNECT_TOKEN" \
         --data '{
           "title": "My Page",
           "slug": "/my-page",
           "description": "A custom page about developer portals",
           "visibility": "public",
           "status": "published",
           "content": "# Welcome to My Dev Portal\nExplore the available APIs below:\n::apis-list\n---\npersist-page-number: true\ncta-text: \"View APIs\"\n---\n"
         }'
    
  12. Puedes ver la nueva página creada en el editor Dev Portal > MyDevPortal > Portal Editor y examinar el Portal Editor.
  13. Ingresar a la URL de la página creada anteriormente:
    curl -I https://$PORTAL_URL/my-page
    
  14. Crear un nuevo recurso tipo API, ejecutar el siguiente comando en el servidor Docker.
    curl -X POST "$KONNECT_CONTROL_PLANE_URL/v3/apis" \
         -H "Accept: application/json"\
         -H "Content-Type: application/json"\
         -H "Authorization: Bearer $DECK_KONNECT_TOKEN" \
         --data '{
           "name": "MyAPI",
           "attributes": {
             "env": [
               "development"
             ],
             "domains": [
               "web",
               "mobile"
             ]
           }
         }'
    
  15. Buscar en la consola gráfica de Konnect y exportar el ID del API como variable de entorno. Lo puedes encontrar en: Dev Portal > APIs > MyAPI.
    export API_ID='87827e-43b-46a-994-f69c246d'
    
  16. Crear y asociar una especificación de API, ejecutar el siguiente comando en el servidor Docker:
    curl -X POST "$KONNECT_CONTROL_PLANE_URL/v3/apis/$API_ID/versions" \
      -H "Accept: application/json" \
      -H "Content-Type: application/json" \
      -H "Authorization: Bearer $DECK_KONNECT_TOKEN" \
      --data '{
        "version": "1.0.0",
        "spec": {
          "content": "{\"openapi\":\"3.0.3\",\"info\":{\"title\":\"Example API\",\"version\":\"1.0.0\"},\"paths\":{\"/example\":{\"get\":{\"summary\":\"Get all examples\",\"responses\":{\"200\":{\"description\":\"Success\"}}},\"post\":{\"summary\":\"Create example\",\"requestBody\":{\"required\":true,\"content\":{\"application/json\":{\"schema\":{\"type\":\"object\",\"properties\":{\"name\":{\"type\":\"string\"}}}}}},\"responses\":{\"201\":{\"description\":\"Created\"}}}},\"/example/{id}\":{\"get\":{\"summary\":\"Get by ID\",\"parameters\":[{\"name\":\"id\",\"in\":\"path\",\"required\":true,\"schema\":{\"type\":\"string\"}}],\"responses\":{\"200\":{\"description\":\"Found\"},\"404\":{\"description\":\"Not Found\"}}}},\"/health\":{\"get\":{\"summary\":\"Health Check\",\"responses\":{\"200\":{\"description\":\"Healthy\"}}}}}}"
        }
      }'
    
  17. Crear y asociar documentación de un API, ejecutar el siguiente comando en el servidor Docker:
    curl -X POST "$KONNECT_CONTROL_PLANE_URL/v3/apis/$API_ID/documents" \
      -H "Accept: application/json" \
      -H "Content-Type: application/json" \
      -H "Authorization: Bearer $DECK_KONNECT_TOKEN" \
      --data '{
        "slug": "task-api-docs",
        "status": "published",
        "title": "Task API Documentation",
        "content": "# Task API\n\n## Overview\nThis API allows clients to manage tasks. Clients can create, retrieve, update, and delete tasks.\n\n## Base URL\n```\nhttps://api.example.com/v1/tasks\n```\n\n## Authentication\nAll endpoints require an API key in the `Authorization` header:\n```\nAuthorization: Bearer YOUR_API_KEY\n```\n\n## Endpoints\n\n### Get All Tasks\n**GET** `/tasks`\n\n**Response:**\n```json\n[\n  {\n    \"id\": 1,\n    \"title\": \"Buy groceries\",\n    \"completed\": false\n  }\n]\n```\n\n### Get Task by ID\n**GET** `/tasks/{id}`\n\n**Response:**\n```json\n{\n  \"id\": 1,\n  \"title\": \"Buy groceries\",\n  \"completed\": false\n}\n```\n\n### Create Task\n**POST** `/tasks`\n\n**Request Body:**\n```json\n{\n  \"title\": \"Go to the gym\"\n}\n```\n\n**Response:**\n```json\n{\n  \"id\": 2,\n  \"title\": \"Go to the gym\",\n  \"completed\": false\n}\n```\n\n### Update Task\n**PUT** `/tasks/{id}`\n\n**Request Body:**\n```json\n{\n  \"title\": \"Buy groceries and fruits\",\n  \"completed\": true\n}\n```\n\n**Response:**\n```json\n{\n  \"id\": 1,\n  \"title\": \"Buy groceries and fruits\",\n  \"completed\": true\n}\n```\n\n### Delete Task\n**DELETE** `/tasks/{id}`\n\n**Response:**\n```\n204 No Content\n```\n\n## Error Codes\n| Code | Message           |\n|------|-------------------|\n| 400  | Bad Request       |\n| 401  | Unauthorized      |\n| 404  | Not Found         |\n| 500  | Internal Error    |\n\n## Changelog\n- v1.0: Initial release"
      }'
    
  18. Extraer y exportar el ID del Gateway Service a asociar con el API. En la consola web: Gateway Manager > workshop-itm > Gateway Services > dev_portal_example-service, Click en el icono de Copy ID.
    export SERVICE_ID=ccb28e-38f-444-87f7-86689dee48
    
  19. Asociar el API con el Gateway Service, ejecutar el siguiente comando en el servidor Docker
    curl -X POST "$KONNECT_CONTROL_PLANE_URL/v3/apis/$API_ID/implementations" \
         -H "Accept: application/json"\
         -H "Content-Type: application/json"\
         -H "Authorization: Bearer $DECK_KONNECT_TOKEN" \
         --data '{
           "service": {
             "control_plane_id": "'$CONTROL_PLANE_ID'",
             "id": "'$SERVICE_ID'"
           }
         }'
    
  20. Publicar el API en el Developer portal, ejecutar el siguiente comando en el servidor Docker:
    curl -X PUT "$KONNECT_CONTROL_PLANE_URL/v3/apis/$API_ID/publications/$PORTAL_ID" \
         -H "Accept: application/json"\
         -H "Content-Type: application/json"\
         -H "Authorization: Bearer $DECK_KONNECT_TOKEN"
    
  21. Para validar que la API fue creada y publicada en tu Portal de Desarrolladores, abrir la siguiente URL en el navegador Web:
    https://$PORTAL_URL/apis