将web端graphql接口复制到postman
目录
将web端graphql接口复制到postman
要在浏览器中使用开发者工具(F12)将 GraphQL 接口请求复制到 Postman,您可以按照以下步骤操作:
1. 打开开发者工具 在浏览器中按 F12
或右键点击页面并选择“检查”以打开开发者工具。
2. 监控网络请求 切换到“Network”(网络)选项卡,然后执行您的 GraphQL 请求操作。
3. 找到 GraphQL 请求 在网络请求列表中找到您的 GraphQL 请求。通常,GraphQL 请求的类型是 POST
,并且 URL 包含 /graphql
。
4. 复制请求 右键点击该请求,然后选择“Copy” > “Copy as cURL” 或者“Copy” > “Copy as fetch”。
5. 在 Postman 中导入请求 打开 Postman,点击“Import”按钮,然后选择“Raw text”选项卡。
6. 粘贴请求 将刚才复制的 cURL 或 fetch 请求粘贴到文本框中,然后点击“Continue”按钮。
7. 检查和发送请求 Postman 会自动解析并导入请求。您可以在 Postman 中检查请求的各个部分(如 URL、Headers、Body),然后点击“Send”按钮发送请求。
示例操作
假设您在浏览器中复制了以下 cURL 请求:
curl 'http://localhost:4000/graphql' \
-H 'Content-Type: application/json' \
--data-binary '{"query":"mutation accept_orders_by_retailer($input: AcceptOrdersByRetailerInput!) { acceptOrdersByRetailer(input: $input) { acceptedOrders { id accepted storeEntitymsStoreId retailerEntitymsEntityId userIp endpoint shopperUsermsUserId shopperUsermsGuestId email totalAmount totalSubtotal totalDiscount totalSalesTax totalShipping status userIp suborders { edges { node { id status subtotal suborderCode } } totalCount } shippingAddress { id lastName middleName firstName company phoneNumber phoneCountryCode countryCode } } serverStatus { code message } } }","variables":{"input":{"orderIds":["order_id_1","order_id_2"]}}}'
将其粘贴到 Postman 的“Import” > “Raw text”中,然后点击“Continue”按钮。Postman 会自动解析并导入请求。
注意事项
确保将
order_id_1
和order_id_2
替换为实际的订单 ID。确保您的 GraphQL 服务器正在运行,并且 URL 是正确的。
这样,您就可以在 Postman 中成功导入并发送 GraphQL 请求了。