axios
and got
HTTP clients in the examples below, but you can use any npm package you’d like on Pipedream, so feel free to experiment with other clients, too.
If you’re developing Pipedream components, you may find the @pipedream/platform
version of axios
helpful for displaying error data clearly in the Pipedream UI.
If you’re new to HTTP, see our glossary of HTTP terms for a helpful introduction.
axios
usage notesaxios
on Pipedream, you’ll just need to import the axios
npm package:
axios
that defines the parameters of the request. For example, you’ll typically want to define the HTTP method and the URL you’re sending data to:
axios
returns a Promise, which is just a fancy way of saying that it makes the HTTP request in the background (asynchronously) while the rest of your code runs. On Pipedream, all asynchronous code must be run synchronously, which means you’ll need to wait for the HTTP request to finish before moving on to the next step. You do this by adding an await
in front of the call to axios
.
Putting all of this together, here’s how to make a basic HTTP request on Pipedream:
resp
contains a lot of information about the response: its data, headers, and more. Typically, you just care about the data, which you can access in the data
property of the response:
GET
request to fetch dataPOST
request to submit dataPOST
request, you pass POST
as the method
, and include the data you’d like to send in the data
object.
GET
request/comments
resource, retrieving data for a specific post by query string parameter: /comments?postId=1
.
headers
object of the axios
request:
1
, 2
, and 3
in the body of an HTTP POST request:
promise.allSettled
, which makes all HTTP requests and returns data on their success / failure. If an HTTP request fails, all other requests will proceed.
axios.get
requests (which are all Promises), and then call Promise.allSettled
to run them in parallel.
When you want to stop future requests when one of the requests fails, you can use Promise.all
, instead:
ThePromise.allSettled()
method returns a promise that resolves after all of the given promises have either fulfilled or rejected, with an array of objects that each describes the outcome of each promise.
It is typically used when you have multiple asynchronous tasks that are not dependent on one another to complete successfully, or you’d always like to know the result of each promise.
In comparison, the Promise returned byPromise.all()
may be more appropriate if the tasks are dependent on each other / if you’d like to immediately reject upon any of them rejecting.
multipart/form-data
request/tmp
directory/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.
/tmp
directorymultipart/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.
$send.http()
to send requests from a limited set of IP addresses./tmp
directory.
Copy this workflow or paste this code into a new Node.js code step:
https://example.com
with the URL you’d like to stream data from, and replace https://example2.com
with the URL you’d like to send the data to. got
streams the content directly, downloading the file using a GET
request and uploading it as a POST
request.
If you need to modify this behavior, see the got
Stream API.
axios
throws an error when the HTTP response code is in the 400-500 range (a client or server error). If you’d like to process the error data instead of throwing an error, you can pass a custom function to the validateStatus
property:
axios
docs for more details.
graphql-request
NPM package:
graphql
package is required for popular GraphQL clients to function, like graphql-request
and urql
.Even though you will not need to use the graphql
code itself in your code step, it’s required to import it in order for graphql-request
to function.app
prop: