Para probar la API de helloworld implementada, haz clic en la pestaña Terminal en Apigee en Cloud Code y, luego, ingresa la siguiente llamada curl:
curl 0:8998/helloworld
Se muestra el siguiente mensaje de error:
Dado que habilitaste la autenticación basada en claves de API cuando creaste el proxy de API, debes pasar una clave de API mediante el parámetro de consulta apikey cuando llamas a la API.
Para obtener una clave de API, debes crear un paquete de prueba y configurar los siguientes recursos de prueba:
Producto de API que se usa para agrupar la API y hacer que esté disponible para los desarrolladores
Desarrollador que creará una app para acceder a la API
App de desarrollador que habilitará el acceso a la API mediante una clave de API
Compila y exporta recursos de prueba
Crea un paquete de prueba:
Coloca el cursor sobre la carpeta tests y haz clic en .
Se abrirá el asistente para crear un paquete de prueba.
Ingresa mytestbundle para el nombre del paquete de prueba y presiona Intro.
Se creó el paquete de prueba.
Expande la carpeta mytestbundle para ver su contenido.
Configura el recurso de prueba del producto de la API:
Coloca el cursor sobre el archivo products.json y haz clic en .
Se abrirá el asistente Crear producto de API.
Ingrese myproduct para el nombre del producto de la API y presione Intro para confirmar y continuar.
Ingrese myproduct para la descripción del producto de la API y presione Intro para confirmar y continuar.
Selecciona helloworld para agregar el proxy de API al producto de API y haz clic en Aceptar.
El archivo products.json se abre en el editor con el nuevo producto de API configurado:
Exporta los recursos de prueba al emulador de Apigee.
Coloca el cursor sobre el paquete de prueba mytestbundle y haz clic en .
Los recursos de prueba activos aparecen en la sección Emuladores de Apigee, como se muestra en la siguiente figura.
Cómo obtener la clave de API
Obtén las credenciales de la clave de API para tu app de desarrollador:
En la sección emulators, en Active test data, haz clic en Active developer apps.
El archivo de configuración de apps activo para desarrolladores se abre en el editor. El archivo contiene credenciales para myproduct, como se destaca en la siguiente figura.
<p><img src="/apigee/docs/api-platform/images/vscode-consumerkey.png" alt="Developer apps with the consumerKey value highlighted."></p>
Copia el valor de consumerKey (sin comillas) para el producto de API myproduct.
Probar su API
Prueba tu API con la clave de API:
Pasa la clave de API en tu llamada a curl mediante el parámetro de búsqueda apikey de la siguiente manera:
curl 0:8998/helloworld?apikey=API_KEY
Se muestra la siguiente respuesta:
Hello, Guest!
¡Felicitaciones! Ejecutaste una API en tu entorno local de forma correcta.
En el siguiente paso, aprenderás cómo cambiar el extremo de destino.
[[["Fácil de comprender","easyToUnderstand","thumb-up"],["Resolvió mi problema","solvedMyProblem","thumb-up"],["Otro","otherUp","thumb-up"]],[["Difícil de entender","hardToUnderstand","thumb-down"],["Información o código de muestra incorrectos","incorrectInformationOrSampleCode","thumb-down"],["Faltan la información o los ejemplos que necesito","missingTheInformationSamplesINeed","thumb-down"],["Problema de traducción","translationIssue","thumb-down"],["Otro","otherDown","thumb-down"]],["Última actualización: 2025-09-04 (UTC)"],[[["\u003cp\u003eThis guide is relevant for both Apigee and Apigee hybrid users, providing instructions on local API testing.\u003c/p\u003e\n"],["\u003cp\u003eTo successfully test an API secured with API key authentication, you must create and configure an API product, a developer, and a developer app.\u003c/p\u003e\n"],["\u003cp\u003eYou create a test bundle where you will configure your test resources, including API products, developers, and developer apps.\u003c/p\u003e\n"],["\u003cp\u003eAfter configuring the test resources, export the test bundle to the Apigee Emulator to make the active test data available, enabling you to retrieve the API key from the active developer app.\u003c/p\u003e\n"],["\u003cp\u003eOnce you have the API key, use it as a query parameter in a curl call to successfully test your API, receiving the "Hello, Guest!" response.\u003c/p\u003e\n"]]],[],null,["# Step 4: Test your API\n\n*This page\napplies to **Apigee** and **Apigee hybrid**.*\n\n\n*View [Apigee Edge](https://docs.apigee.com/api-platform/get-started/what-apigee-edge) documentation.*\n\n\u003cbr /\u003e\n\nTo test the deployed `helloworld` API, click the **Terminal** tab\nin Apigee in Cloud Code and enter the following curl call: \n\n```\ncurl 0:8998/helloworld\n```\n\nThe following error message is displayed:\n\nBecause you enabled API key-based authentication when creating the API proxy, you need to pass an API key using the `apikey` query parameter when calling the API.\n\nTo obtain an API key, you need to create a test bundle and configure the following test resources:\n\n- **API product** used to bundle the API and make it available to developers.\n\n- **Developer** that will create an app to access the API.\n\n- **Developer app** that will enable access to the API using an API key.\n\n| **Note:** The examples in this section use `0` for the host value and `8998` for the port value. You can configure the port values, as described in [Managing the Apigee Emulator.](/apigee/docs/api-platform/local-development/vscode/manage-apigee-emulator) If you get an error when using `0`, substitute `localhost` for the `0`: \n|\n| ```\n| curl localhost:8998/helloworld\n| ```\n\nBuild and Export test resources\n-------------------------------\n\n1. Create a test bundle:\n 1. Position your cursor over the **test data** folder and click .\n\n The **Create test bundle** wizard opens.\n 2. Enter **mytestbundle** for the test bundle name and press **Enter** .\n\n The test bundle is created.\n 3. Expand the **mytestbundle** folder to view its contents.\n\n2. Configure the API product test resource:\n 1. Position your cursor over the **products.json** file and click .\n\n The **Create API product** wizard opens.\n\n\n 2. Enter **myproduct** for the name of the API product and press **\u003ckbd\u003eEnter\u003c/kbd\u003e** to confirm and proceed.\n 3. Enter **myproduct** for the description of the API product and press **\u003ckbd\u003eEnter\u003c/kbd\u003e** to confirm and proceed.\n 4. Select **helloworld** to add the API proxy to the API product and click **OK** .\n\n The `products.json` file is opened in the editor with the new API product configured: \n\n ```\n [\n {\n \"attributes\": [\n {\n \"name\": \"sample_attribute_0\",\n \"value\": \"sample_attribute_value_0\"\n }\n ],\n \"scopes\": [],\n \"environments\": [],\n \"apiResources\": [\n \"/\",\n \"/*\",\n \"/**\"\n ],\n \"quota\": \"100\",\n \"quotaInterval\": \"1\",\n \"quotaTimeUnit\": \"minute\",\n \"name\": \"myproduct\",\n \"displayName\": \"myproduct\",\n \"proxies\": [\n \"helloworld\"\n ]\n }\n ]\n ```\n3. Configure the developer test resource:\n 1. Position your cursor over the **developers.json** file and click .\n\n\n The **Create developer** wizard opens.\n\n\n 2. Enter the following values at the prompts and press **\u003ckbd\u003eEnter\u003c/kbd\u003e** to confirm and proceed:\n - Developer email: **ahamilton@example.com**\n - Username: **ahamilton**\n - First name: **Alex**\n - Last name: **Hamilton**\n\n The `developers.json` file is opened in the editor with the new developer configured: \n\n ```\n [\n {\n \"attributes\": [\n {\n \"name\": \"sample_attribute_0\",\n \"value\": \"sample_attribute_value_0\"\n }\n ],\n \"email\": \"ahamilton@example.com\",\n \"userName\": \"ahamilton\",\n \"firstName\": \"Alex\",\n \"lastName\": \"Hamilton\"\n }\n ]\n ```\n4. Configure the developer app test resource:\n 1. Position your cursor over the **developerapps.json** file and click .\n\n\n The **Create developer app** wizard opens.\n\n\n 2. Select **ahamilton@example.com** as the owner of the app.\n 3. Enter the following values at the next set of prompts and press **Enter** to confirm and proceed:\n - App name: **myapp**\n - Description: **myapp**\n - Callback URL: **Leave blank**\n - Select **myproduct** to add it to the app and click **OK**.\n - Select **never** for the expiry value.\n\n The `developerapps.json` file is opened in the editor with the new app configured: \n\n ```\n [\n {\n \"attributes\": [\n {\n \"name\": \"sample_attribute_0\",\n \"value\": \"sample_attribute_value_0\"\n }\n ],\n \"developerEmail\": \"ahamilton@example.com\",\n \"name\": \"myapp\",\n \"displayName\": \"myapp\",\n \"callbackUrl\": \"\",\n \"apiProducts\": [\n \"myproduct\"\n ],\n \"expiryType\": \"never\"\n }\n ]\n ```\n5. Export the test resources to the Apigee Emulator. Position the cursor over the **mytestbundle** test bundle and click .\n\n\n | **Note:** If multiple [containers for the Apigee Emulator](/apigee/docs/api-platform/local-development/vscode/manage-apigee-emulator#add-container) are running, you are prompted to select the container to which you want to deploy the environment.\n\n The active test resources appears in the Apigee Emulators section, as shown in the following figure.\n\nObtain the API key\n------------------\n\nObtain the API key credentials for your developer app:\n\n1. In the **emulators** section, under **Active test data** , click **Active developer apps** .\n\n The active developer apps configuration file is opened in the editor. The file contains credentials for `myproduct`, as highlighted in the following figure.\n2. Copy the `consumerKey` value (without the quotes) for the `myproduct` API product.\n\n\u003cbr /\u003e\n\nTest your API\n-------------\n\nTest your API with the API key:\n\n1. Pass the API key in your curl call using the `apikey` query parameter, as follows: \n\n ```\n curl 0:8998/helloworld?apikey=\u003cvar translate=\"no\"\u003eAPI_KEY\u003c/var\u003e\n ```\n\n\n The following response is returned: \n\n ```\n Hello, Guest!\n ```\n\n\u003cbr /\u003e\n\n**Congratulations!** You've successfully run an API in your local environment.\n\nIn the next step, you'll learn how to change the target endpoint.\n\n\n[1](/apigee/docs/api-platform/local-development/vscode/tutorial-create-workspace)\n\n\n[2](/apigee/docs/api-platform/local-development/vscode/tutorial-create-proxy)\n\n\n[3](/apigee/docs/api-platform/local-development/vscode/tutorial-deploy)\n\n\n[4](/apigee/docs/api-platform/local-development/vscode/tutorial-test)\n\n\n[(NEXT) Step 5: Change the target endpoint](/apigee/docs/api-platform/local-development/vscode/tutorial-change-target-endpoint)\n\n\n[6](/apigee/docs/api-platform/local-development/vscode/tutorial-attach-policy)\n\n\n[7](/apigee/docs/api-platform/local-development/vscode/tutorial-deploy-apigee)\n\n\n[8](/apigee/docs/api-platform/local-development/vscode/tutorial-promote)\n\n\u003cbr /\u003e"]]