HTTP Request

Learn about writing HTTP requests in Laminar Editor

Basic Structure

In Laminar, to codify an HTTP request, you must update your flow program to return an object with the following format:

{
  "lam.httpRequest": {
    "method": "POST", // (or "GET", "PUT", "DELETE")
    "url": "https://api.example.com/endpoint",
    "pathParams": { /* optional */ },
    "queryParams": { /* optional */ },
    "headers": { /* optional */ },
    "body": { /* optional */ }
  }
}

Examples

  1. Let's start with a basic GET request to fetch users:

(payload) => {
  const { input } = payload;
  
  return {
    "lam.httpRequest": {
      "method": "GET",
      "url": "https://api.example.com/users"
    }
  }
}
  1. Now, let's create a user with a POST request:

(payload) => {
  const { input } = payload;
  
  return {
    "lam.httpRequest": {
      "method": "POST",
      "url": "https://api.example.com/products",
      "body": {
        "name": "John Doe",
        "email": "[email protected]"
      }
    }
  }
}

Optional Attributes

Now let's explore each optional attribute and how to use them effectively.

Path Parameters

Path parameters are used to replace dynamic segments in your URL path.

Example:

(payload) => {
  const { input } = payload;
  
  return {
    "lam.httpRequest": {
      "method": "GET",
      "url": "https://api.example.com/users/{userId}",
      "pathParams": {
        "userId": "12345"
      }
    }
  }
}

This will resolve to a request to https://api.example.com/users/12345.

Query Parameters

Query parameters add a query string to your URL.

Example:

(payload) => {
  const { input } = payload;
  
  return {
    "lam.httpRequest": {
      "method": "GET",
      "url": "https://api.example.com/users",
      "queryParams": {
        "page": 1,
        "limit": 10,
        "sort": "name"
      }
    }
  }
}

This will resolve to a request to https://api.example.com/users?page=1&limit=10&sort=name

Headers

Headers allow you to send additional information with your request.

Example:

(payload) => {
  const { input } = payload;
  
  return {
    "lam.httpRequest": {
      "method": "GET",
      "url": "https://api.example.com/users",
      "headers": {
        "Authorization": "Bearer token123",
        "Content-Type": "application/json",
        "Accept-Language": "en-US"
      }
    }
  }
}

Body

The body contains data sent with the request. It's typically used with POST, PUT, and PATCH methods.

Example:

(payload) => {
  const { input } = payload;
  
  return {
    "lam.httpRequest": {
      "method": "POST",
      "url": "https://api.example.com/users",
      "headers": {
        "Content-Type": "application/json"
      },
      "body": {
        "name": "Jane Smith",
        "email": "[email protected]",
        "role": "admin"
      }
    }
  }
}

Multiple Requests

Laminar also supports sending multiple HTTP requests in a single operation. This is useful for batch processing or when you need to perform several related actions at once. See HTTP Request Batching.

You can make your batch requests more powerful by using dynamic path parameters. This is especially useful when working with lists of IDs:

(payload) => {
  const { input } = payload;
  
  return userIds.map(userId => ({
  "lam.httpRequest": {
    "method": "GET",
    "url": "https://api.example.com/users/{userId}",
    "pathParams": {
      "userId": userId
    }
  }
}));

Last updated

Was this helpful?