Skip to content

[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

Draft
wants to merge 1 commit into
base: production
Choose a base branch
from
Draft

[BRAPI]Rest API guide #22056

wants to merge 1 commit into from

Conversation

daisyfaithauma
Copy link
Contributor

Summary

Screenshots (optional)

Documentation checklist

  • The documentation style guide has been adhered to.
  • If a larger change - such as adding a new page- an issue has been opened in relation to any incorrect or out of date information that this PR fixes.
  • Files which have changed name or location have been allocated redirects.

Copy link
Contributor

hyperlint-ai bot commented Apr 29, 2025

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 Summary

Updated the REST API documentation to include new examples and added a comprehensive guide for extracting blog post content using the markdown endpoint.

  • Added examples for using the Workers Binding API and REST API in the browser rendering documentation.
  • Introduced a new guide for extracting blog post content as markdown using the markdown endpoint.
  • Provided detailed instructions for setting up environment variables and making API requests.

Modified Files

  • src/content/docs/browser-rendering/get-started.mdx

Added Files

  • src/content/docs/browser-rendering/how-to/markdown-extraction.mdx

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 hyperlint-ignore label to the PR. Future changes won't trigger a Hyperlint review.

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 hyperlint-ignore to the PR to ignore the link check for this PR.

export CF_API_TOKEN="your-api-token-with-edit-permissions"
```

## 2: Make the API Request and save the raw JSON
Copy link
Contributor

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.

Copy link
Contributor Author

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?

Copy link
Contributor

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.

Copy link
Contributor

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?

Copy link
Contributor

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

Copy link
Contributor Author

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.

Copy link
Contributor

@omarmosid omarmosid May 1, 2025

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();

Copy link
Contributor

@kodster28 kodster28 May 1, 2025

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants