requests
HTTP client package available in Python to send HTTP requests, but you can use any PyPi package you’d like on Pipedream.
Basic requests
usage notes
No need to run pip install
, just import requests
at the top of your step’s code and it’s available for your code to use.
To use requests
on Pipedream, you’ll just need to import the requests
PyPi package:
r
contains a lot of information about the response: its content, headers, and more. Typically, you just care about the content, which you can access in the text
property of the response:
r.encoding
, which is determined based on the HTTP headers.
If you’re dealing with JSON data, you can call r.json()
to decode the content as JSON:
r.json()
raises an exception.
Making a GET
request
GET requests typically are for retrieving data from an API. Below is an example.
Making a POST
request
POST
request, pass a dictionary with the data you’d like to send to the data
argument. Requests automatically form-encodes the data when the request is made.
The code example above will NOT set the
Content-Type
header, meaning it will NOT be set to application/json
.If you want the header set to application/json
and don’t want to encode the dict
yourself, you can pass it using the json
parameter and it will be encoded automatically:Passing query string parameters to a GET
request
Retrieve fake comment data on a specific post using JSONPlaceholder, a free mock API service. Here, you fetch data from the /comments
resource, retrieving data for a specific post by query string parameter: /comments?postId=1
.
params
keyword argument, like above. When you do, requests
automatically URL-encodes the parameters for you, which you’d otherwise have to do manually.
Sending a request with HTTP headers
To add HTTP headers to a request, pass a dictionary to theheaders
parameter:
Sending a request with a secret or API key
Most APIs require you authenticate HTTP requests with an API key or other token. Please review the docs for your service to understand how they accept this data. Here’s an example showing an API key passed in an HTTP header:Sending files
An example of sending a previously stored file in the workflow’s/tmp
directory:
Downloading a file to the /tmp
directory
This example shows you how to download a file to a file in the /tmp
directory. This can be especially helpful for downloading large files: it streams the file to disk, minimizing the memory the workflow uses when downloading the file.
Uploading a file from the /tmp
directory
This example shows you how to make a multipart/form-data
request with a file as a form part. You can store and read any files from the /tmp
directory.
This can be especially helpful for uploading large files: it streams the file from disk, minimizing the memory the workflow uses when uploading the file.
IP addresses for HTTP requests made from Pipedream workflows
By default, HTTP requests made from Pipedream can come from a large range of IP addresses. If you need to restrict the IP addresses HTTP requests come from, you can Use a Pipedream VPC to route all outbound HTTP requests through a single IP address.Using an HTTP proxy to proxy requests through another host
By default, HTTP requests made from Pipedream can come from a range of IP addresses. If you need to make requests from a single IP address, you can route traffic through an HTTP proxy:Paginating API requests
When you fetch data from an API, the API may return records in “pages”. For example, if you’re trying to fetch a list of 1,000 records, the API might return those in groups of 100 items. Different APIs paginate data in different ways. You’ll need to consult the docs of your API provider to see how they suggest you paginate through records.Sending a GraphQL request
Construct a GraphQL query as a string and then using the requests library to send it to the GraphQL server:Sending an authenticated GraphQL request
Authenticate your connected accounts in Pipedream with GraphQL requests usingpd.inputs[appName]["$auth"]
: