Add APIRequest component for making HTTP requests
This commit is contained in:
parent
9958ce76fd
commit
a7dddbcb1d
1 changed files with 4 additions and 0 deletions
|
|
@ -2,6 +2,7 @@ import asyncio
|
||||||
from typing import List, Optional
|
from typing import List, Optional
|
||||||
|
|
||||||
import httpx
|
import httpx
|
||||||
|
import json
|
||||||
|
|
||||||
from langflow import CustomComponent
|
from langflow import CustomComponent
|
||||||
from langflow.schema import Record
|
from langflow.schema import Record
|
||||||
|
|
@ -26,10 +27,12 @@ class APIRequest(CustomComponent):
|
||||||
"headers": {
|
"headers": {
|
||||||
"display_name": "Headers",
|
"display_name": "Headers",
|
||||||
"info": "The headers to send with the request.",
|
"info": "The headers to send with the request.",
|
||||||
|
"input_types": ["dict"]
|
||||||
},
|
},
|
||||||
"body": {
|
"body": {
|
||||||
"display_name": "Body",
|
"display_name": "Body",
|
||||||
"info": "The body to send with the request (for POST, PATCH, PUT).",
|
"info": "The body to send with the request (for POST, PATCH, PUT).",
|
||||||
|
"input_types": ["dict"]
|
||||||
},
|
},
|
||||||
"timeout": {
|
"timeout": {
|
||||||
"display_name": "Timeout",
|
"display_name": "Timeout",
|
||||||
|
|
@ -53,6 +56,7 @@ class APIRequest(CustomComponent):
|
||||||
raise ValueError(f"Unsupported method: {method}")
|
raise ValueError(f"Unsupported method: {method}")
|
||||||
|
|
||||||
data = body if body else None
|
data = body if body else None
|
||||||
|
data = json.dumps(data)
|
||||||
try:
|
try:
|
||||||
response = await client.request(
|
response = await client.request(
|
||||||
method, url, headers=headers, content=data, timeout=timeout
|
method, url, headers=headers, content=data, timeout=timeout
|
||||||
Loading…
Add table
Add a link
Reference in a new issue