Content-Length: 464939 | pFad | http://github.com/lowcoder-org/lowcoder/pull/1803/commits/0ae6c23dc902f49f7c79e557c8b28b6f3ea18971

01 [Feat]: Add Import from cURL in Query Library by iamfaran · Pull Request #1803 · lowcoder-org/lowcoder · GitHub
Skip to content

[Feat]: Add Import from cURL in Query Library #1803

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jun 24, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
console log curl to json
  • Loading branch information
iamfaran committed Jun 23, 2025
commit 0ae6c23dc902f49f7c79e557c8b28b6f3ea18971
1 change: 1 addition & 0 deletions client/packages/lowcoder/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"types": "src/index.sdk.ts",
"dependencies": {
"@ant-design/icons": "^5.3.0",
"@bany/curl-to-json": "^1.2.8",
"@codemirror/autocomplete": "^6.11.1",
"@codemirror/commands": "^6.3.2",
"@codemirror/lang-css": "^6.2.1",
Expand Down
90 changes: 90 additions & 0 deletions client/packages/lowcoder/src/components/CurlImport.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import React, { useState } from "react";
import { Modal, Input, Button, message } from "antd";
import { trans } from "i18n";
import parseCurl from "@bany/curl-to-json";
const { TextArea } = Input;
interface CurlImportModalProps {
open: boolean;
onCancel: () => void;
onSuccess: (parsedData: any) => void;
}

export function CurlImportModal(props: CurlImportModalProps) {
const { open, onCancel, onSuccess } = props;
const [curlCommand, setCurlCommand] = useState("");
const [loading, setLoading] = useState(false);

const handleImport = async () => {
if (!curlCommand.trim()) {
message.error("Please enter a cURL command");
return;
}

setLoading(true);
try {
// Parse the cURL command using the correct import
const parsedData = parseCurl(curlCommand);
console.log("CURL JSON", parsedData)



// Log the result for now as requested
// console.log("Parsed cURL data:", parsedData);

// Call success callback with parsed data
onSuccess(parsedData);

// Reset form and close modal
setCurlCommand("");
onCancel();

message.success("cURL command imported successfully!");
} catch (error: any) {
console.error("Error parsing cURL command:", error);
message.error(`Failed to parse cURL command: ${error.message}`);
} finally {
setLoading(false);
}
};

const handleCancel = () => {
setCurlCommand("");
onCancel();
};

return (
<Modal
title="Import from cURL"
open={open}
onCancel={handleCancel}
footer={[
<Button key="cancel" onClick={handleCancel}>
Cancel
</Button>,
<Button key="import" type="primary" loading={loading} onClick={handleImport}>
Import
</Button>,
]}
width={600}
>
<div style={{ marginBottom: 16 }}>
<div style={{ marginBottom: 8, fontWeight: 500 }}>
Paste cURL Command Here
</div>
<div style={{ marginBottom: 12, color: "#666", fontSize: "12px" }}>
Hint: Try typing in the following curl command and then click on the 'Import' button:
curl -X GET https://mock-api.appsmith.com/users
</div>
<TextArea
value={curlCommand}
onChange={(e) => setCurlCommand(e.target.value)}
placeholder="curl -X POST \
-H 'Content-Type: application/json' \
'https://generativelanguage.googleapis.com/v1beta/models/{MODEL_ID}:{GENERATE_CONTENT_API}?key={GEMINI_API_KEY}' -d '@request.json'"
rows={8}
style={{ fontFamily: "monospace" }}
/>
</div>
</Modal>
);
}
24 changes: 24 additions & 0 deletions client/packages/lowcoder/src/components/ResCreatePanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { getUser } from "../redux/selectors/usersSelectors";
import DataSourceIcon from "./DataSourceIcon";
import { genRandomKey } from "comps/utils/idGenerator";
import { isPublicApplication } from "@lowcoder-ee/redux/selectors/applicationSelector";
import { CurlImportModal } from "./CurlImport";

const Wrapper = styled.div<{ $placement: PageType }>`
width: 100%;
Expand Down Expand Up @@ -230,6 +231,7 @@ export function ResCreatePanel(props: ResCreateModalProps) {
const { onSelect, onClose, recentlyUsed, datasource, placement = "editor" } = props;
const [isScrolling, setScrolling] = useState(false);
const [visible, setVisible] = useState(false);
const [curlModalVisible, setCurlModalVisible] = useState(false);

const isPublicApp = useSelector(isPublicApplication);
const user = useSelector(getUser);
Expand All @@ -244,6 +246,19 @@ export function ResCreatePanel(props: ResCreateModalProps) {
setScrolling(top > 0);
}, 100);

const handleCurlImportSuccess = (parsedData: any) => {
// For now just log the result as requested
console.log("cURL import successful:", parsedData);

// Create a new REST API query with the parsed data
// We'll pass the parsed data as extra info to be used when creating the query
onSelect(BottomResTypeEnum.Query, {
compType: "restApi",
dataSourceId: QUICK_REST_API_ID,
curlData: parsedData
});
};

return (
<Wrapper $placement={placement}>
<Title $shadow={isScrolling} $placement={placement}>
Expand Down Expand Up @@ -331,6 +346,10 @@ export function ResCreatePanel(props: ResCreateModalProps) {
<ResButton size={buttonSize} identifier={"streamApi"} onSelect={onSelect} />
<ResButton size={buttonSize} identifier={"alasql"} onSelect={onSelect} />
<ResButton size={buttonSize} identifier={"graphql"} onSelect={onSelect} />
<DataSourceButton size={buttonSize} onClick={() => setCurlModalVisible(true)}>
<DataSourceIcon size="large" dataSourceType="restApi" />
Import from cURL
</DataSourceButton>
</DataSourceListWrapper>
</div>

Expand Down Expand Up @@ -374,6 +393,11 @@ export function ResCreatePanel(props: ResCreateModalProps) {
onCancel={() => setVisible(false)}
onCreated={() => setVisible(false)}
/>
<CurlImportModal
open={curlModalVisible}
onCancel={() => setCurlModalVisible(false)}
onSuccess={handleCurlImportSuccess}
/>
</Wrapper>
);
}
12 changes: 11 additions & 1 deletion client/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1682,6 +1682,15 @@ __metadata:
languageName: node
linkType: hard

"@bany/curl-to-json@npm:^1.2.8":
version: 1.2.8
resolution: "@bany/curl-to-json@npm:1.2.8"
dependencies:
minimist: ^1.2.8
checksum: 4f2c095c3e3194e9e3e717cf766a66c8ca320c2f10b118d52a8d8d2b842b6760af656a966ec3ce9e9cf774909b2507a2d1417c7f3d98b6773f5ae935be9191b6
languageName: node
linkType: hard

"@bcoe/v8-coverage@npm:^0.2.3":
version: 0.2.3
resolution: "@bcoe/v8-coverage@npm:0.2.3"
Expand Down Expand Up @@ -14095,6 +14104,7 @@ coolshapes-react@lowcoder-org/coolshapes-react:
resolution: "lowcoder@workspace:packages/lowcoder"
dependencies:
"@ant-design/icons": ^5.3.0
"@bany/curl-to-json": ^1.2.8
"@codemirror/autocomplete": ^6.11.1
"@codemirror/commands": ^6.3.2
"@codemirror/lang-css": ^6.2.1
Expand Down Expand Up @@ -15476,7 +15486,7 @@ coolshapes-react@lowcoder-org/coolshapes-react:
languageName: node
linkType: hard

"minimist@npm:^1.2.0, minimist@npm:^1.2.6":
"minimist@npm:^1.2.0, minimist@npm:^1.2.6, minimist@npm:^1.2.8":
version: 1.2.8
resolution: "minimist@npm:1.2.8"
checksum: 75a6d645fb122dad29c06a7597bddea977258957ed88d7a6df59b5cd3fe4a527e253e9bbf2e783e4b73657f9098b96a5fe96ab8a113655d4109108577ecf85b0
Expand Down








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/lowcoder-org/lowcoder/pull/1803/commits/0ae6c23dc902f49f7c79e557c8b28b6f3ea18971

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy