Capture cURL requests

Updated 1 week ago by Rahul Lahiri

There are three options for importing cURL requests into API Studio.

  • Importing a single cURL request: See here
  • Capturing cURL requests from scripts: Covered in this article.
  • Importing collections: See here

Steps to capture cURL requests from script

You can capture cURL requests issued by a script on your local machine by sending the cURL request to the target API via the API Studio proxy. You will need to make a change to cURL request in order for it to be captured via the proxy.

  • Point the request to the API Studio proxy running at http://localhost:9000 (or the port where you configured the proxy to run).
  • Change the path of the API calls to add the service name to the path in the format servicename/API-path.
  • Configure API Studio to forward the request to the actual service.
  • Select the collection to store the captured cURL requests in.

Example

Original cURL request:

cURL 'https://moviebook.meshdynamics.io/restsql/query?name=born+free'

In order to forward the request to the destination via the API Studio proxy, you need to make the following changes.

  1. In the API Editor, set up a proxy configuration for the url(s).
  • Click the Proxy settings button.
  • In the Service configurations tab, create a configuration with a service name moviebook for the url https://moviebook.meshdynamics.io. Save the configuration.
If you want to capture cURL requests to multiple services, add all the services in this configuration.
  1. Select the proxy configuration from dropdown.
  1. Select the collection where the captured requests will be stored.
  • Click the Proxy Settings button.
  • Click the Mock Settings tab, and select the destination collection from the Save to collection dropdown.
  1. In your script, change the request to send it to the localhost:9000 (or the port where you configured the proxy to run). Add the service name configured in the previous step as the first path parameter.
cURL 'https://localhost:9000/moviebook/restsql/query?name=born+free'
Note that the first path parameter now is the service followed by the original API path to be queried. In this example, we are using the service name moviebook that we configured earlier.

Now if you run the script, the cURL requests above will be automatically captured by API Studio.


How did we do?