-
Notifications
You must be signed in to change notification settings - Fork 6.5k
[BRAPI]Rest API guide #22056
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
base: production
Are you sure you want to change the base?
[BRAPI]Rest API guide #22056
Conversation
Howdy and thanks for contributing to our repo. The Cloudflare team reviews new, external PRs within two (2) weeks. If it's been two weeks or longer without any movement, please tag the PR Assignees in a comment. We review internal PRs within 1 week. If it's something urgent or has been sitting without a comment, start a thread in the Developer Docs space internally. PR Change SummaryUpdated the REST API documentation to include new examples and added a comprehensive guide for extracting blog post content using the markdown endpoint.
Modified Files
Added Files
How can I customize these reviews?Check out the Hyperlint AI Reviewer docs for more information on how to customize the review. If you just want to ignore it on this PR, you can add the Note specifically for link checks, we only check the first 30 links in a file and we cache the results for several hours (for instance, if you just added a page, you might experience this). Our recommendation is to add |
export CF_API_TOKEN="your-api-token-with-edit-permissions" | ||
``` | ||
|
||
## 2: Make the API Request and save the raw JSON |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question about this tutorial..... if we're already running a Python script, couldn't we just have steps 2-4 included in the Python script as well?
Seems like it would simplify things a lot.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure how to do that. Maybe you could guide me in the right direction?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure how to do that. Maybe you could guide me in the right direction?
Python has a requests
library, which could be used to make the cURL request.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose the broader question is also.... why Python here?
If we're using the REST API, all of the other examples are using the TypeScript SDK... so why would we change languages from what we provide in the rest of the docs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am a little confused too..
if our end goal is to generate an md file for a blog post, we could perhaps do it in a worker?
And if that is the case, it would make more sense to use BR bindings (instead of the REST API). We could all the BR work in the worker and finally return the md file as the worker response.
If it's not possible to do it in a worker, instead of python, we should do it as a node script with the typescript SDK or directly calling the REST API through fetch. Lemme know if you need any help figuring this out
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@omarmosid I specifically did not do it with Workers because we do not have any guide of using our REST API endpoints. The goal is to show how to use our REST API endpoints.
Please assist in doing it through the fetch API.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something like this? (using node)
// saveMarkdown.js
const fs = require('fs');
async function downloadMarkdown() {
const accountId = '<accountId>';
const apiToken = '<apiToken>';
const blogUrl = 'https://example.com';
const endpoint = `https://api.cloudflare.com/client/v4/accounts/${accountId}/browser-rendering/markdown`;
try {
const response = await fetch(endpoint, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${apiToken}`
},
body: JSON.stringify({ url: blogUrl })
});
if (!response.ok) {
throw new Error(`Failed to fetch markdown: ${response.status} ${response.statusText}`);
}
const data = await response.json();
const markdown = data.result;
const filename = 'output.md';
fs.writeFileSync(filename, markdown);
console.log(`Markdown saved to ${filename}`);
} catch (error) {
console.error('Error:', error.message);
}
}
downloadMarkdown();
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@omarmosid I specifically did not do it with Workers because we do not have any guide of using our REST API endpoints. The goal is to show how to use our REST API endpoints. Please assist in doing it through the fetch API.
If it's something that fundamentally doesn't make sense to do via the REST API, shouldn't we be looking for another use case?
We don't want to promote an inefficient approach to a problem, even if it's illustrative.
Summary
Screenshots (optional)
Documentation checklist