4. Send Your First API Request

Updated 1 month ago by Rahul Lahiri

Here we will introduce you to the basic capabilities of the API Studio:

  • Send an API request to an endpoint
  • Create a reference response for a request
  • Identify changes in the API behavior from the reference

Sample App: MovieInfo

We provide a sample app, MovieInfo, and a sandbox to get you going with API Studio. This includes:

  • Live endpoints running in the Mesh Dynamics cloud
  • A test suite with some example requests

We will send the test requests to the sandbox for this section.

API Editor UI

There are two panes in the API editor.

  • The left hand side is the test request and response. In this case, we will create a request and the expected response manually. Note that in actual usage, you will likely not create the responses manually unless you are creating a mock for an API that does not exist yet. 
  • The right hand side is the actual request sent to the service and the response we received. 

The two panes enable us to compare the expected and actual requests and responses. 

Create API Request

Select app

Select the MovieInfo application from the list of applications – the drop-down list is available at the top left.

Create API Request

Let's create the first request by hand rather than taking it from a collection. Enter the following in the request box next to the drop down saying “GET”.

{{{url}}}/minfo/listmovies?filmName=agent truman

You will notice that the query param filmName has been added below the request.

Create environment variable

Notice the {{{url}}} variable in the request. Environment variables allow setting different values without modifying the request. We will define the variable next.

  • Create an environment called “sample” from the top right gears icon.
  • Add a variable called url, and set the value to https://moviebook.meshdynamics.io.

Create expected response

Add a sample JSON response that we expect manually. Copy the following snippet of JSON to the response section on the left hand side. 

[ 
{
"actors_lastnames": [
"PALTROW",
"KILMER",
"NEESON",
"NOLTE",
"WILLIAMS",
"HOFFMAN",
"WEST"
],
"display_actors": [
"SANDRA KILMER",
"WARREN NOLTE",
"REESE WEST",
"JAYNE NEESON"
],
"film_id": 6,
"title": "AGENT TRUMAN"
}
]

The left hand side should now look like:

Save Request

Save the request to a collection.

  • Click the Save button
  • From the dialog, create a collection with the name movieinfo-sample.
  • Save the request to the collection.

Run Request and Compare Result

  • Run the request by clicking the Run button
  • The response from the API will be shown on the right hand side.
  • Click the Diff button to compare the new response with the previous response.

The differences are shown with the sections with no changes collapsed by default. You can expand the collapsed sections by clicking the expand icons.

Next steps

Next, we will get into using API Studio to drive requests to a service running locally in the laptop, which will in turn make API requests to other services in the cloud. Let us set up the sample application provided for this next step.


How did we do?