-
Notifications
You must be signed in to change notification settings - Fork 10.2k
[BRAPI] json endpoint docs #20981
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
[BRAPI] json endpoint docs #20981
Changes from 5 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
5d378cd
json endpoint docs
daisyfaithauma e013509
reorder
daisyfaithauma 0ecfead
docs: Update JSON endpoint documentation with new examples and structure
omarmosid 1ec81ad
docs: Add links endpoint
omarmosid fedb13f
minor edits
daisyfaithauma 09bcd50
collapsed lines
daisyfaithauma 03b2e27
title
daisyfaithauma bc060e8
Update json-endpoint.mdx
kathayl bd7ab7b
Update json-endpoint.mdx
kathayl 8bff474
Update links-endpoint.mdx
kathayl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
225 changes: 225 additions & 0 deletions
225
src/content/docs/browser-rendering/rest-api/json-endpoint.mdx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,225 @@ | ||
| --- | ||
| pcx_content_type: how-to | ||
| title: Capture structured data | ||
| sidebar: | ||
| order: 9 | ||
| --- | ||
|
|
||
| The `/json` endpoint extracts structured data from a webpage. You can specify the expected output using either a `prompt` or a `response_format` parameter which accepts a JSON schema. The endpoint returns the extracted data in JSON format. | ||
|
|
||
| ## Parameters | ||
|
|
||
| | Parameter | Mandatory | Note | | ||
| | --------------- | --------- | ---------------------------------------------------------------------------- | | ||
| | URL | yes | The URL of the webpage to extract data from. | | ||
| | prompt | no | Must supply one of `prompt` or `response_format`. | | ||
| | response_format | no | Must supply one of `prompt` or `response_format`. May include a JSON schema. | | ||
|
|
||
| ## Basic Usage | ||
|
|
||
| ### With a Prompt and JSON schema | ||
|
|
||
| This example captures webpage data by providing both a prompt and a JSON schema. The prompt guides the extraction process, while the JSON schema defines the expected structure of the output. | ||
|
|
||
| ```bash | ||
| curl --request POST 'https://api.cloudflare.com/client/v4/accounts/CF_ACCOUNT_ID/browser-rendering/json' \ | ||
| --header 'authorization: Bearer CF_API_TOKEN' \ | ||
| --header 'content-type: application/json' \ | ||
| --data '{ | ||
| "url": "https://developers.cloudflare.com/", | ||
| "prompt": "Get me the list of AI products", | ||
| "response_format": { | ||
| "type": "json_schema", | ||
| "json_schema": { | ||
| "type": "object", | ||
| "properties": { | ||
| "products": { | ||
| "type": "array", | ||
| "items": { | ||
| "type": "object", | ||
| "properties": { | ||
| "name": { | ||
| "type": "string" | ||
| }, | ||
| "link": { | ||
| "type": "string" | ||
| } | ||
| }, | ||
| "required": [ | ||
| "name" | ||
| ] | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| }' | ||
| ``` | ||
|
|
||
|
|
||
| ```json output | ||
| { | ||
| "success": true, | ||
| "result": { | ||
| "products": [ | ||
| { | ||
| "name": "Build a RAG app", | ||
| "link": "https://developers.cloudflare.com/workers-ai/tutorials/build-a-retrieval-augmented-generation-ai/" | ||
| }, | ||
| { | ||
| "name": "Workers AI", | ||
| "link": "https://developers.cloudflare.com/workers-ai/" | ||
| }, | ||
| { | ||
| "name": "Vectorize", | ||
| "link": "https://developers.cloudflare.com/vectorize/" | ||
| }, | ||
| { | ||
| "name": "AI Gateway", | ||
| "link": "https://developers.cloudflare.com/ai-gateway/" | ||
| }, | ||
| { | ||
| "name": "AI Playground", | ||
| "link": "https://playground.ai.cloudflare.com/" | ||
| } | ||
| ] | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ### With only a prompt | ||
|
|
||
| In this example, only a prompt is provided. The endpoint will use the prompt to extract the data, but the response will not be structured according to a JSON schema. | ||
| This is useful for simple extractions where you don't need a specific format. | ||
|
|
||
| ```bash | ||
| curl --request POST 'https://api.cloudflare.com/client/v4/accounts/CF_ACCOUNT_ID/browser-rendering/json' \ | ||
| --header 'authorization: Bearer CF_API_TOKEN' \ | ||
| --header 'content-type: application/json' \ | ||
| --data '{ | ||
| "url": "https://developers.cloudflare.com/", | ||
| "prompt": "get me the list of AI products" | ||
| }' | ||
| ``` | ||
|
|
||
|
|
||
| ```json output | ||
|
|
||
| "success": true, | ||
| "result": { | ||
| "AI Products": [ | ||
| "Build a RAG app", | ||
| "Workers AI", | ||
| "Vectorize", | ||
| "AI Gateway", | ||
| "AI Playground" | ||
| ] | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ### With only a JSON schema (no prompt) | ||
|
|
||
| In this case, you supply a JSON schema via the `response_format` parameter. The schema defines the structure of the extracted data. | ||
|
|
||
| ```bash | ||
| curl --request POST 'https://api.cloudflare.com/client/v4/accounts/CF_ACCOUNT_ID/browser-rendering/json' \ | ||
| --header 'authorization: Bearer CF_API_TOKEN' \ | ||
| --header 'content-type: application/json' \ | ||
| --data '"response_format": { | ||
| "type": "json_schema", | ||
| "json_schema": { | ||
| "type": "object", | ||
| "properties": { | ||
| "products": { | ||
| "type": "array", | ||
| "items": { | ||
| "type": "object", | ||
| "properties": { | ||
| "name": { | ||
| "type": "string" | ||
| }, | ||
| "link": { | ||
| "type": "string" | ||
| } | ||
| }, | ||
| "required": [ | ||
| "name" | ||
| ] | ||
| } | ||
| } | ||
| } | ||
| } | ||
| }' | ||
| ``` | ||
|
|
||
|
|
||
| ```json output | ||
| { | ||
| "success": true, | ||
| "result": { | ||
| "products": [ | ||
| { | ||
| "name": "Workers", | ||
| "link": "https://developers.cloudflare.com/workers/" | ||
| }, | ||
| { | ||
| "name": "Pages", | ||
| "link": "https://developers.cloudflare.com/pages/" | ||
| }, | ||
| { | ||
| "name": "R2", | ||
| "link": "https://developers.cloudflare.com/r2/" | ||
| }, | ||
| { | ||
| "name": "Images", | ||
| "link": "https://developers.cloudflare.com/images/" | ||
| }, | ||
| { | ||
| "name": "Stream", | ||
| "link": "https://developers.cloudflare.com/stream/" | ||
| }, | ||
| { | ||
| "name": "Build a RAG app", | ||
| "link": "https://developers.cloudflare.com/workers-ai/tutorials/build-a-retrieval-augmented-generation-ai/" | ||
| }, | ||
| { | ||
| "name": "Workers AI", | ||
| "link": "https://developers.cloudflare.com/workers-ai/" | ||
| }, | ||
| { | ||
| "name": "Vectorize", | ||
| "link": "https://developers.cloudflare.com/vectorize/" | ||
| }, | ||
| { | ||
| "name": "AI Gateway", | ||
| "link": "https://developers.cloudflare.com/ai-gateway/" | ||
| }, | ||
| { | ||
| "name": "AI Playground", | ||
| "link": "https://playground.ai.cloudflare.com/" | ||
| }, | ||
| { | ||
| "name": "Access", | ||
| "link": "https://developers.cloudflare.com/cloudflare-one/policies/access/" | ||
| }, | ||
| { | ||
| "name": "Tunnel", | ||
| "link": "https://developers.cloudflare.com/cloudflare-one/connections/connect-networks/" | ||
| }, | ||
| { | ||
| "name": "Gateway", | ||
| "link": "https://developers.cloudflare.com/cloudflare-one/policies/gateway/" | ||
| }, | ||
| { | ||
| "name": "Browser Isolation", | ||
| "link": "https://developers.cloudflare.com/cloudflare-one/policies/browser-isolation/" | ||
| }, | ||
| { | ||
| "name": "Replace your VPN", | ||
| "link": "https://developers.cloudflare.com/learning-paths/replace-vpn/concepts/" | ||
| } | ||
| ] | ||
| } | ||
| } | ||
| ``` | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.