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.
- Ingresar al menú llamado Dev Portal.
- En el submenú llamado Portals, dar click en el botón + Create a new portal
- Elejir la opción de visibilidad como Public portal
- Colocarle de nombre MyDevPortal y dar click en el botón Create and continue
- A continuación, dar click en el botón Save
- Luego dar click en el botón Go to overview
- Debes copiar y guardar en un lugar seguro el ID y URL del nuevo Developer Portal
- 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' - Cargar la variables de entorno con el siguiente comando:
source env.sh - 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 - - 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" }' - Puedes ver la nueva página creada en el editor
Dev Portal > MyDevPortal > Portal Editory examinar el Portal Editor. - Ingresar a la URL de la página creada anteriormente:
curl -I https://$PORTAL_URL/my-page - 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" ] } }' - 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' - 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\"}}}}}}" } }' - 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" }' - Extraer y exportar el ID del
Gateway Servicea 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 - Asociar el API con el
Gateway Service, ejecutar el siguiente comando en el servidor Dockercurl -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'" } }' - 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" - 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