Concepts Flows Flow Types 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:
Copy {
"lam.httpRequest": {
"method": "POST", // (or "GET", "PUT", "DELETE")
"url": "https://api.example.com/endpoint",
"pathParams": { /* optional */ },
"queryParams": { /* optional */ },
"headers": { /* optional */ },
"body": { /* optional */ }
}
}
Examples
Let's start with a basic GET request to fetch users:
Copy (payload) => {
const { input } = payload;
return {
"lam.httpRequest": {
"method": "GET",
"url": "https://api.example.com/users"
}
}
}
Now, let's create a user with a POST request:
Copy (payload) => {
const { input } = payload;
return {
"lam.httpRequest": {
"method": "POST",
"url": "https://api.example.com/products",
"body": {
"name": "John Doe",
"email": "john@example.com"
}
}
}
}
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:
Copy (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:
Copy (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 allow you to send additional information with your request.
Example:
Copy (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:
Copy (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": "jane@example.com",
"role": "admin"
}
}
}
}
Multiple Requests
You can make your batch requests more powerful by using dynamic path parameters. This is especially useful when working with lists of IDs:
Copy (payload) => {
const { input } = payload;
return userIds.map(userId => ({
"lam.httpRequest": {
"method": "GET",
"url": "https://api.example.com/users/{userId}",
"pathParams": {
"userId": userId
}
}
}));