# Making an HTTP request
curl is already preinstalled in Bash steps, we recommend using it for making HTTP requests in your code for sending or requesting data from APIs or webpages.
# Making a
You can use
curl to perform
GET requests from websites or APIs directly.
# Get the current weather in San Francisco WEATHER=`curl --silent https://wttr.in/San\ Francisco\?format=3` echo $WEATHER # Produces: # San Francisco: 🌫 +48°F
--silent flag with
curl to suppress extra extra diagnostic information that
curl produces when making requests.
This enables you to only worry about the body of the response so you can visualize it with tools like
# Making a
curl can also make
POSTs requests as well. The
-X flag allow you to specify the HTTP method you'd like to use for an HTTP request.
-d flag is for passing data in the
curl --silent -X POST https://postman-echo.com/post -d 'name=Bulbasaur&id=1' # To store the API response in a variable, interpolate the response into a string and store it in variable RESPONSE=`curl --silent -X POST https://postman-echo.com/post -d 'name=Bulbasaur&id=1'` # Now the response is stored as a variable echo $RESPONSE
# Using API key authentication
Some APIs require you to authenticate with a secret API key.
curl has an
-h flag where you can pass your API key as a token.
For example, here's how to retrieve mentions from the Twitter API:
# Define the "Authorization" header to include your Twitter API key curl --silent -X POST -h "Authorization: Bearer $(<your api key here>)" https://api.twitter.com/2/users/@pipedream/mentions