Skip to main content
Build the future with Agentforce at TDX in San Francisco or on Salesforce+ on March 5–6. Register now.
Estimación de tiempo
Temas
Preguntar a la comunidad

Test the API Specification

It’s time to test your API specification to prototype the implementation. In this step, you activate the API Mocking Service. The mocking service enables you to simulate the behavior of an API specification. The mocking service provides a test link to an API. The mocking service returns the responses (both HTTP status codes and example payloads) that are defined in your API specification. These responses are valuable for testing or exploring how your API behaves.

Navigate to the QuickStart-Store API in the Design Center that you built in the last unit. On the right-hand side of the screen, click the Mocking Service Configuration icon as shown in the following screenshot.

Arrow pointing to the Mocking Service Configuration icon on API designer screen.

Then, in the Service Settings, click the slider in the Make Public section. 

Arrow pointing to the slider to make mocking service public in Service Settings.

After the Mocking Service is made public, the slider changes to blue with a check mark. You see a new parameter called Public link with a copy button for copying that public link to your clipboard. Click Copy.

Next, we’ll guide you through calling the API two separate times; once using the interactivity that’s built into the documentation and once from outside the Anypoint Platform.

Note

The mocking service is only meant for testing and not for production use.

Send a Request to Mocking Service

Now that the mocking service is public, click the Documentation icon on the right-hand side of the screen as shown in the following screenshot.

Arrow pointing to the Documentation icon on API designer screen.

The Documentation pane includes the API summary where you can try a request and see the response.

  1. Click GET following /products/{productId} to view the endpoint details.
  2. Click Try it.
  3. To test the request, enter the following values.
    • productId*: 2
    • Credentials User name: mulesoft
    • Credentials Password: mulesoft
  1. Click Send.
Note

The product Id, User name, and password values used here are arbitrary. The mocking service request will work with any value you choose.

Scroll the pane a bit more and you see that the mocking service returned a 200 response with the example body.

The same API call can also be tested outside of the Anypoint Platform by performing a similar request with another web client, such as curl using the following.

curl -X GET {{yourMockingServiceUrl}}/products/2 -u mulesoft:mulesoft

For the mocking service URL, use the URL that you copied when you activated the mocking service earlier (without the curly braces shown in the previous example).

Note: Since you’re using the mocking service, changing the product number at the end of the URL will return the same sample response.

The mocking service URL can be shared with other stakeholders and can be used for testing during the design phase.

Comparta sus comentarios sobre Trailhead en la Ayuda de Salesforce.

Nos encantaría conocer su experiencia con Trailhead. Ahora puede acceder al nuevo formulario de comentarios cuando quiera desde el sitio de la Ayuda de Salesforce.

Más información Continuar para compartir comentarios