Skip to main content
La Trailblazer Community en Slack ya está en fase beta abierta. Únase y conéctese en tiempo real. Únase a nosotros en Slack

Perform API Calls

Learning Objectives

After completing this unit, you’ll be able to:

  • Explain how to use a REST client to execute API calls.
  • Distinguish between GET and POST requests.
  • Analyze API responses, including HTTP status codes and headers.

In earlier units, you explored how APIs connect systems, enable secure integrations, and use HTTP methods like GET and POST. You also saw how Mule United Airport leveraged APIs to improve operations and deliver real-time updates to passengers.

This unit builds on that foundation by showing you how to interact directly with APIs using tools like REST clients. You’ll use the API Console in MuleSoft’s Anypoint Exchange to practice making API calls and analyzing responses against a mock server. We recommend you follow the hands-on steps via your desktop or laptop browser.

Work with REST Clients

When working with APIs, developers need efficient ways to test and debug requests. Instead of writing code for every interaction, they use tools called REST clients, which provide user-friendly interfaces for interacting with REST APIs.

A woman faces a choice between a confusing maze labeled ’Manual API Testing’ and a clear open door labeled ’REST Client’.

A smiling woman walks confidently toward a large sign pointing to ’REST Client’.

What Are REST Clients?

REST clients, like Postman and Advanced REST Client (ARC), are essential tools for making API calls and analyzing responses. These tools help developers by:

  • Simplifying Requests: Compose and send requests without writing code.
  • Supporting HTTP Methods: Work with GET, POST, PUT, DELETE, and PATCH.
  • Customizing Headers and Parameters: Include authentication tokens, query parameters, and other essential details.
  • Interpreting Responses: View HTTP status codes, headers, and payloads in a readable format.

Why Use REST Clients?

REST clients help with several tasks.

  • Testing APIs: Ensure endpoints work as expected before incorporating them into applications.
  • Troubleshooting Issues: Identify errors by examining status codes or payload details.
  • Learning APIs: Explore an unfamiliar API’s behavior and documentation interactively.

Using a REST client saves time, enabling developers to focus on designing solutions rather than debugging request code.

Explore an API Using MuleSoft’s Training Portal

Now that you understand how APIs enable applications to exchange data, let’s take a closer look at how an API is structured and how it communicates. In this walkthrough, you’ll explore a real API portal to see how endpoints, methods, and responses are documented.

You won’t need to install any tools or write code, just follow along using your browser. We recommend using your desktop or laptop for this experience.

Access the Developer Training Portal

You’ve just joined the team at Mule United Airport. Your job is to explore the American Flights API and learn how to retrieve flight schedules and manage bookings using REST methods like GET and POST.

  1. Open a browser and go to https://anypoint.mulesoft.com/exchange/portals/muletraining/.
  2. Click Training: American Flights API to open its API portal.
  3. In the navigation, click /flights to view its available methods.
  4. Select the GET method under /flights
    1. You will see there is an available query parameter: destination.
    2. Scroll down the page to view the Headers and Responses sections.
  5. In the navigation panel, select the DELETE method for /flights/{ID}.
    1. Note the ID URI parameter is a string and is required.
    2. To test this endpoint, enter 3 as the value for the ID field. This will simulate deleting the flight with ID 3.
  6. Browse the rest of the available resources to see how different operations are supported.
Note

In a real-world scenario, you'd use the GET method first to retrieve a list of flights, then choose one of the IDs returned. For now, use 3 as a known working example.

Make Practice Requests in the API Console

Now that you’ve familiarized yourself with the structure and documentation of the American Flights API, it’s time to get hands-on. In this section, you’ll send requests through the API Console built into Anypoint Exchange. The console sends them to a mock server that returns example responses, so you can practice without live credentials or usage limits.

Send a GET Request

  1. Stay in the Training: American Flights API portal and select the /flights GET method again.
  2. In the API Console located on the right side, confirm that Mocking Service is selected in the Select server field.
  3. In the Headers section, enter the following values. The mock server accepts any value, but it requires both.
    1. client_id: trailhead-id
    2. client_secret: trailhead-secret
  4. (Optional) In the Query Parameters section, select a code for destination, such as SFO. A live API would return only the flights for that destination. The mock returns the same two example flights either way.
  5. Click Send.

Review the response:

  • Look at the JSON body to see the returned flight information. You should see two example flights.
  • Look at the response headers, such as Content-Type.
    • Click on the 3 dots.
    • Select Response details.

Submit a POST Request

  1. In the API Console, select the /flights POST method.
  2. Enter the same values for the client_id and client_secret values headers if they’re not carried over.
  3. The console includes a sample request body to show you the expected format. Take a moment to review it, then replace or modify the values to create a new flight of your own.
{
  "code": "GQ574",
  "price": 399,
  "departureDate": "2016/12/20",
  "origin": "ORD",
  "destination": "SFO",
  "emptySeats": 200,
  "plane": {
    "type": "Boeing 747",
    "totalSeats": 400
  }
}
  1. When you're ready, click Send to submit the request and check the response.
  2. Look for a 201 Created response. The response body says the flight was added, but the mock doesn’t save it.

The Mocking Service returns example responses, but it still checks that your request is well formed. It requires the client_id and client_secret headers and a complete request body, and it returns an error when they’re missing. You’ll learn more about the Mocking Service and how to use it in Module 3.

Trigger and Analyze Errors

Now let’s see what happens when something goes wrong. APIs respond with different status codes depending on the problem. Testing these responses helps you understand how to debug and handle errors, which is something every API developer needs to know.

Try the following scenarios using the POST /flights method:

Missing Required Data

  • In the Body, remove “code” field.
  • Click Send.
  • You should receive a 400 Bad Request response, indicating the API couldn’t process the request. The response body names the missing field.

Missing Headers

  • Try removing the client_id or client_secret from the Headers.
  • Send the request again.
  • You’ll see a 400 Bad Request error. The response body says which required header is missing.

Each of these errors tells a story. Check the status code, response body, and headers—just like you would when diagnosing an issue in a real integration.

Compare With a Live API

The mock server checks that a request is well formed, but it doesn’t enforce who is calling. A live API usually sits behind a gateway that does. Here is what the live API returns when a request has no credentials.

HTTP/1.1 401 Unauthorized
Content-Type: application/json; charset=UTF-8
www-authenticate: Client-ID-Enforcement
 {
   "error": "Invalid client id or secret"
 }
 ```
A **401 Unauthorized** response means the request didn’t include valid credentials. Gateways can also limit how often a client calls an API. When a client goes over its limit, the API returns **429 Too Many Requests**:
```
 HTTP/1.1 429 Too Many Requests
 x-ratelimit-limit: 3
 x-ratelimit-remaining: 0
{
   "error": "Quota has been exceeded"
}
```

The x-ratelimit headers report the request limit, the requests remaining, and the time until the limit resets.

Understand Why This Matters

Now you’ve explored how to read API documentation, send practice GET and POST requests, and interpret responses like a developer would. You also got a look at common errors and how to troubleshoot them.

These are the building blocks of working with APIs. They help you understand how systems exchange data and what to look for when something goes wrong.

You’ve also seen how organizations like Mule United Airport use APIs to connect systems and deliver better, faster services. Replacing outdated, siloed tools with connected APIs creates more flexibility and a better experience for users.

This practice sets you up for the next step, learning how to design your own APIs with confidence.

Comparta sus comentarios de Trailhead en la Ayuda de Salesforce.

Nos encantaría saber más sobre su experiencia con Trailhead. Ahora puede acceder al nuevo formulario de comentarios en cualquier momento en el sitio de Ayuda de Salesforce.

Más información Continuar a Compartir comentarios